llllmz

导航

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

2024年9月14日

76. 最小覆盖子串

摘要: 跟着别人的代码履了一遍,明天自己再重写遍。 class Solution { public: map<char, int> tstr, sstr; bool isContained(){ for(auto tchar : tstr){ if(tchar.second > sstr[tchar.fir 阅读全文

posted @ 2024-09-14 22:56 神奇的萝卜丝 阅读(8) 评论(0) 推荐(0)

2024年9月12日

904. 水果成篮

摘要: 改不了C的思维 class Solution { public: int totalFruit(vector<int>& fruits) { if(fruits.size() <= 2) return fruits.size(); int left = 0, right = 0, curNum = 阅读全文

posted @ 2024-09-12 21:35 神奇的萝卜丝 阅读(13) 评论(0) 推荐(0)

2024年9月10日

209. 长度最小的子数组

摘要: 滑动窗口!! class Solution { public: int minSubArrayLen(int target, vector<int>& nums) { int left = 0, right = 0, sum = nums[0]; int minLength = INT_MAX; w 阅读全文

posted @ 2024-09-10 22:46 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0)

2024年9月8日

977. 有序数组的平方

摘要: sort 一下 class Solution { public: vector<int> sortedSquares(vector<int>& nums) { vector<int> ret; for(int num : nums){ ret.push_back(pow(num, 2)); } so 阅读全文

posted @ 2024-09-08 16:47 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0)

844. 比较含退格的字符串

摘要: c++字符串还是不太熟练 class Solution { public: bool backspaceCompare(string s, string t) { return dealString(s) == dealString(t); } private: string dealString( 阅读全文

posted @ 2024-09-08 16:37 神奇的萝卜丝 阅读(15) 评论(0) 推荐(0)

283. 移动零

摘要: class Solution { public: void moveZeroes(vector<int>& nums) { int head = 0, curIndex = 0; for(; curIndex < nums.size(); ++curIndex){ if(nums[curIndex] 阅读全文

posted @ 2024-09-08 16:28 神奇的萝卜丝 阅读(7) 评论(0) 推荐(0)

2024年9月6日

26. 删除有序数组中的重复项

摘要: class Solution { public: int removeDuplicates(vector<int>& nums) { int head = 0, curIndex = 0, target = INT_MIN; for(; curIndex < nums.size(); ++curIn 阅读全文

posted @ 2024-09-06 21:22 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0)

27. 移除元素

摘要: 像个漏斗一样把元素筛出来就好了。 class Solution { public: int removeElement(vector<int>& nums, int val) { int head = 0, curIndex = 0; for(; curIndex < nums.size(); ++ 阅读全文

posted @ 2024-09-06 21:15 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0)

2024年9月5日

367. 有效的完全平方数

摘要: class Solution { public: bool isPerfectSquare(int num) { int left = 0, right = num; while(left <= right){ int mid = left + (right - left) / 2; if(pow( 阅读全文

posted @ 2024-09-05 21:51 神奇的萝卜丝 阅读(10) 评论(0) 推荐(0)

69. x 的平方根

摘要: 这题也是利用二分查找来计算。 首先区间是[0,x]。通过x/2的平方判断应该区间左移还是区间右移,同时值得注意的是要记录mid的平方小于x的mid值,因为比如8的平方根是2,所以平方小于x的mid要记录。 class Solution { public: int mySqrt(int x) { in 阅读全文

posted @ 2024-09-05 21:47 神奇的萝卜丝 阅读(14) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 ··· 35 下一页
点击右上角即可分享
微信分享提示