随笔分类 -  题解 / LeetCode

水!!!
摘要:2024-7-1 LCP 40. 心算挑战 代码实现 class Solution { public: int maxmiumScore(vector<int>& cards, int cnt) { int n = size(cards); std::sort(cards.rbegin(), car 阅读全文
posted @ 2024-08-01 09:52 sleeeeeping 阅读(40) 评论(0) 推荐(0)
摘要:剑指Offer题单及题解 题目顺序为牛客上剑指Offer专题 JZ3、数组中重复的数字 分析 可以直接对数组进行排序,通过判断首末数字大小来判断数字越界情况,注意数组为空的情况。发现 \(0 \leq nums[i] \leq n - 1\), 因此直接开一个数组判断是否有重复数字即可,返回第一个重 阅读全文
posted @ 2024-07-29 18:55 sleeeeeping 阅读(54) 评论(0) 推荐(0)
摘要:2024-7-1 2065. 最大化一张图中的路径价值 分析 注意观察到至多走十条边,因此直接爆搜即可。 代码实现 class Solution { public: int maximalPathQuality(vector<int>& values, vector<vector<int>>& ed 阅读全文
posted @ 2024-07-01 11:06 sleeeeeping 阅读(73) 评论(0) 推荐(0)
摘要:2024-6-1 2928. 给小朋友们分糖果 I 分析 枚举所有可能的方案数即可 代码实现 class Solution { public: int distributeCandies(int n, int limit) { int ans = 0; for (int a = 0; a <= li 阅读全文
posted @ 2024-06-01 08:55 sleeeeeping 阅读(54) 评论(0) 推荐(0)
摘要:2024-5-6 1463. 摘樱桃 II 代码实现 class Solution { public: int cherryPickup(vector<vector<int>>& grid) { int n = size(grid), m = size(grid[0]); std::vector f 阅读全文
posted @ 2024-05-07 16:01 sleeeeeping 阅读(42) 评论(0) 推荐(0)