Leetcode - 147双周赛

一、3407. 子字符串匹配模式

题目链接
在这里插入图片描述
字符串匹配问题,把字符串 p 分成两段 、,i 是 ’ * ’ 的下标,判断 s 是否包含这两段,且这两段处于不相交 && 有前后关系

代码如下:

class Solution {
   
   
    public boolean hasMatch(String s, String p) {
   
   
        int idx = p.indexOf('*');
        int i = s.indexOf(p.substring(0, idx));
        return i>=0 && s.substring(i+idx).contains(p.substring(idx+1));
    }
}

二、3408. 设计任务管理器

题目链接
在这里插入图片描述
使用哈希存当前每个 taskId,对应的 userId 和 priority,再使用堆存储 taskId 和 priority,按照 priority 排序,如果优先级相同,按照 taskId 排序。

  • TaskManager(),将数据存入哈希表和堆
  • add(),将数据存入哈希表和堆
  • edit(),更新哈希表,将更新后的数据存入堆
  • rmv(),更新哈希表 execTop(),不断的将数据排出堆,使用懒删除,如果当前数据存储在哈希表中,返回当前的 userId

代码如下:

class TaskManager {
   
   
    Map<Integer, int[]> map = new HashMap<>();
    PriorityQueue<int[]> que = new PriorityQueue<>((x,y)->x[1]==y[1]?y[0]-x[0]:y[1]-x[1]);
    public TaskManager(List<List<Integer>> tasks) {
   
   
        for(List<Integer> x : tasks){
   
   
            int userId = x.get(0), taskId = x.get(1), priority = x.get(2);
            map.put(taskId, new int[]{
   
   userId, priority});
            que.offer(new int[]{
   
   taskId, priority});
        }    
    }
    
    public void add(int userId, int taskId, int priority) {
   
   
        map.put(taskId, new int[]{
   
   userId, priority});
        que.offer(new int[]{
   
   taskId, priority});
    }
    
    public void edit(int taskId, int newP) {
   
   
        int[] t = map.get(taskId);
        t[1] = newP;
        map.put(taskId, t);
        que.offer(new int[]{
   
   taskId, t[1]});
    }
    
    public void rmv(int taskId) {
   
   
        map.remove(taskId);
    }
    
    public int execTop() {
   
   
        while(!que.isEmpty()){
   
   
            int[] t = que.poll();
            if(map.containsKey(t[
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一叶祇秋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值