leetcode第119场双周赛 - 2023 - 12 - 9

比赛地址 :

https://leetcode.cn/contest/biweekly-contest-119/

t1 :

直接哈希表 加 暴力 统计就行了

复制代码
class Solution {
public:
    vector<int> findIntersectionValues(vector<int>& nums1, vector<int>& nums2) {
        unordered_map<int,int> mp1,mp2;
        int n = nums1.size() , m = nums2.size();
        for(int& x : nums1) mp1[x]++;
        for(int& x : nums2) mp2[x]++;
        int a = 0 ,b = 0 ;
        for(int i=0;i<n;i++){
            if(mp2.find(nums1[i])!=mp2.end()){
                a++;
            }
        }
        for(int j = 0;j<m;j++){
            if(mp1.find(nums2[j])!=mp1.end()){
                b++;
            }
        }
        vector<int> ans;
        ans.push_back(a);
        ans.push_back(b);
        return ans;
    }
};

t2

直接模拟即可

复制代码
class Solution {
public:
    bool pd(char a, char b){
        if(a==b) return true;
        else if(a==b-1 || a==b+1) return true;
        else return false;
    }
    int removeAlmostEqualCharacters(string w) {
        // 直接模拟即可
        int n = w.size();
        int ans = 0;
        for(int i=0;i<n;i++){
            int j = i+1;
            while(j<n && pd(w[j-1],w[j])) j++;
            int len = j - i ;
            ans += len / 2;
            i = j - 1 ;
        }
        return ans;
    }
};

t3

直接滑动窗口来记录每个数的频次,维护一个滑动窗口满足题目条件;

复制代码
class Solution {
public:
    int maxSubarrayLength(vector<int>& nums, int k) {
        int n = nums.size();
        int l = 0 , r = 0 ;
        int ans = 0 ;
        unordered_map<int,int> mp;
        while(r < n){
            mp[nums[r]]++;
            while(mp[nums[r]]>k){
                mp[nums[l++]]--;
            }
            ans = max(ans,r-l+1);
            r ++;
        }
        return ans;
    }
};

t4

相关推荐
CoovallyAIHub19 小时前
中科大DSAI Lab团队多篇论文入选ICCV 2025,推动三维视觉与泛化感知技术突破
深度学习·算法·计算机视觉
NAGNIP20 小时前
Serverless 架构下的大模型框架落地实践
算法·架构
moonlifesudo20 小时前
半开区间和开区间的两个二分模版
算法
moonlifesudo20 小时前
300:最长递增子序列
算法
CoovallyAIHub1 天前
港大&字节重磅发布DanceGRPO:突破视觉生成RLHF瓶颈,多项任务性能提升超180%!
深度学习·算法·计算机视觉
CoovallyAIHub1 天前
英伟达ViPE重磅发布!解决3D感知难题,SLAM+深度学习完美融合(附带数据集下载地址)
深度学习·算法·计算机视觉
聚客AI2 天前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
大怪v2 天前
前端:人工智能?我也会啊!来个花活,😎😎😎“自动驾驶”整起!
前端·javascript·算法
惯导马工2 天前
【论文导读】ORB-SLAM3:An Accurate Open-Source Library for Visual, Visual-Inertial and
深度学习·算法
骑自行车的码农2 天前
【React用到的一些算法】游标和栈
算法·react.js