uacs2024

导航

上一页 1 2 3 4 5 6 7 8 9 ··· 24 下一页

2024年12月28日 #

leetcode 746. 使用最小花费爬楼梯

摘要: 746. 使用最小花费爬楼梯 class Solution { public: int minCostClimbingStairs(vector<int>& cost) { int n = cost.size(); vector<int> dp(n+1);//dp[i]代表到达第 i 层的最小花费 阅读全文

posted @ 2024-12-28 15:53 ᶜʸᵃⁿ 阅读(11) 评论(0) 推荐(0)

leetcode 475. 供暖器

摘要: 475. 供暖器 没做出来🤡 法一:排序 + 二分查找 class Solution { public: //lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的。 //在从小到大的排序数组中,lower_bound(begin,end,n 阅读全文

posted @ 2024-12-28 15:10 ᶜʸᵃⁿ 阅读(18) 评论(0) 推荐(0)

2024年12月27日 #

leetcode 826. 安排工作以达到最大收益

摘要: 826. 安排工作以达到最大收益 首先是自己写的构思代码 class Solution { public: int maxProfitAssignment(vector<int>& difficulty, vector<int>& profit, vector<int>& worker){ sort 阅读全文

posted @ 2024-12-27 20:39 ᶜʸᵃⁿ 阅读(5) 评论(0) 推荐(0)

leetcode 870. 优势洗牌

摘要: 870. 优势洗牌 没做出来🤡 题解 class Solution { public: //类比田忌赛马,数组中最小值即下等马,最大值上等马。每次用nums1中的下等马去跟nums2中的下等马pk //如果干得过就干,干不过就用nums1中的下等马去当炮灰,去干nums2中的上等马 //在本题中, 阅读全文

posted @ 2024-12-27 19:17 ᶜʸᵃⁿ 阅读(16) 评论(0) 推荐(0)

2024年12月20日 #

leetcode 2576. 求出最多标记下标

摘要: 2576. 求出最多标记下标 题解: 这道题从左往右扫描和从右往左扫描都是错的。 比如 : 1 1 1 1 2 2 2 4 ,从右往左,如果将倒数的2 和 4 匹配了,那么剩下的都不能匹配了。但实际上全部都能匹配。 比如: 1 2 2 2 5 5 5 5,从左往右,如果将 1 和 2 匹配,两个 2 阅读全文

posted @ 2024-12-20 21:10 ᶜʸᵃⁿ 阅读(14) 评论(0) 推荐(0)

leetcode 2592. 最大化数组的伟大值

摘要: 2592. 最大化数组的伟大值 法一:排序 丑陋的代码 class Solution { public: int maximizeGreatness(vector<int>& nums) { sort(nums.begin(),nums.end()); int size = nums.size(), 阅读全文

posted @ 2024-12-20 17:06 ᶜʸᵃⁿ 阅读(10) 评论(0) 推荐(0)

leetcode 8. 字符串转换整数 (atoi)

摘要: 8. 字符串转换整数 (atoi) 丑陋的代码 class Solution { public: int myAtoi(string s) { int i = 0,size = s.size(); bool isPositive = true; long res = 0; while(s[i] == 阅读全文

posted @ 2024-12-20 15:58 ᶜʸᵃⁿ 阅读(11) 评论(0) 推荐(0)

2024年12月16日 #

leetcode 1481. 不同整数的最少数目

摘要: 1481. 不同整数的最少数目 法一: class Solution { public: int findLeastNumOfUniqueInts(vector<int>& arr, int k) { unordered_map<int,int> numAdded; for(int &num : a 阅读全文

posted @ 2024-12-16 14:49 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0)

2024年12月14日 #

leetcode 866. 回文质数

摘要: 866. 回文质数 想着开大数组,用质数筛选的方法。但是开大数组超内存了🤡 class Solution { public: bool isPrime[200000001]; bool isPalind(int &num){ string str = to_string(num); int i = 阅读全文

posted @ 2024-12-14 16:00 ᶜʸᵃⁿ 阅读(12) 评论(0) 推荐(0)

2024年12月13日 #

leetcode 228. 汇总区间

摘要: 228. 汇总区间 class Solution { public: vector<string> summaryRanges(vector<int>& nums) { int size = nums.size(); if(size == 1) return {to_string(nums[0])} 阅读全文

posted @ 2024-12-13 19:58 ᶜʸᵃⁿ 阅读(11) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 ··· 24 下一页