IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 数据结构与算法 -> Leetcode第 259 场周赛 -> 正文阅读

[数据结构与算法]Leetcode第 259 场周赛

总结:

本次比赛难度适中,第三题这种题目边界分情况讨论清楚,比如说:枚举的是边长,依次枚举正方形四个顶点…
第四题的话,稍难,观察数据范围,发现长度最长的子序列为7,这是这道题的出发点,暴力枚举答案,并且在 O ( n ) O(n) O(n)的时间判断重复的次数,从大到小枚举,保证字典序最大,细节还是比较多的

5875. 执行操作后的变量值

class Solution {
public:
    int finalValueAfterOperations(vector<string>& operations) {
        int x = 0;
        for (auto& str : operations)
            if (str[1] == '+') x ++ ;
            else x -- ;

        return x;
    }
};

5876. 数组美丽值求和

思路:维护前缀最大值和后缀最小值

class Solution {
public:
    int sumOfBeauties(vector<int>& a) {
        int n = a.size();
        vector<int> minn(n + 1);
        minn[n - 1] = a[n - 1];
        for (int i = n - 2; i >= 1; i -- ) 
            minn[i] = min(a[i], minn[i + 1]);
        
        int s = 0, pre = a[0];
        for (int i = 1; i <= n - 2; i ++ ) {
            if (a[i] > pre && a[i] < minn[i + 1]) s += 2;
            else if (a[i] > a[i - 1] && a[i] < a[i + 1]) s += 1;
            pre = max(pre, a[i]);
        }
        return s;
    }
};

5877. 检测正方形

大模拟:枚举边长

class DetectSquares {
public:
    int f[1001][1001];
    DetectSquares() {
        memset(f, 0, sizeof f);
    }
    
    void add(vector<int> point) {
        f[point[0]][point[1]] ++ ;
    }
    
    int count(vector<int> point) {
        int res = 0, x = point[0], y = point[1];
        for (int i = 1; i <= min(x, 1000 - y); i ++ )
            res += f[x - i][y] * f[x][y + i] * f[x - i][y + i];
        for (int i = 1; i <= min(1000 - x, 1000 - y); i ++ )
            res += f[x + i][y] * f[x][y + i] * f[x + i][y + i];
        for (int i = 1; i <= min(x, y); i ++ )
            res += f[x - i][y] * f[x][y - i] * f[x - i][y - i];
        for (int i = 1; i <= min(1000 - x, y); i ++ )
            res += f[x + i][y] * f[x][y - i] * f[x + i][y - i];
        return res;
    }
};

/**
 * Your DetectSquares object will be instantiated and called as such:
 * DetectSquares* obj = new DetectSquares();
 * obj->add(point);
 * int param_2 = obj->count(point);
 */

最后一题不会…

5878. 重复 K 次的最长子序列

class Solution {
public:
    vector<string> v[8];

    bool check(string t, string s, int k) {
        int cnt = 0;
        for (int i = 0, j = 0; i < s.size(); i ++ ) {
            if (s[i] == t[j]) {
                j ++ ;
                if (j == t.size()) {
                    cnt ++ ;
                    j = 0;
                }
            }
        }
        return cnt >= k;
    }

    string longestSubsequenceRepeatedK(string s, int k) {
        v[0].push_back("");
        int l = 1;
        for (; l < 8; l ++ ) {
            for (auto str : v[l - 1]) {
                for (char ch = 'z'; ch >= 'a'; ch -- ) {
                    if (check(str + ch, s, k))
                        v[l].push_back(str + ch);
                }
            }
            if (v[l].empty()) break;
        }
        l -- ;
        return v[l][0];
    }
};
  数据结构与算法 最新文章
【力扣106】 从中序与后续遍历序列构造二叉
leetcode 322 零钱兑换
哈希的应用:海量数据处理
动态规划|最短Hamilton路径
华为机试_HJ41 称砝码【中等】【menset】【
【C与数据结构】——寒假提高每日练习Day1
基础算法——堆排序
2023王道数据结构线性表--单链表课后习题部
LeetCode 之 反转链表的一部分
【题解】lintcode必刷50题<有效的括号序列
上一篇文章      下一篇文章      查看所有文章
加:2021-09-20 16:00:39  更:2021-09-20 16:01:32 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 8:18:08-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码