llllmz

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

1 2 3 下一页

合集-科软力扣学习记录

34. 在排序数组中查找元素的第一个和最后一个位置
摘要:这题还蛮有意思的,看了下解析,分成两部分分开来求解。 左右边界都是普通的二分查找算法,重点就是当等于的时候的处理,左边界函数等于目标值的时候,要记录当前mid的值作为边界,同时区间要向左移。 反过来,右边界的话,区间要向右移动。记得记录相等时候的mid值,最后一次相等记录的值也就是这个边界值。 cl 阅读全文

posted @ 2024-09-04 17:43 神奇的萝卜丝 阅读(7) 评论(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 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

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 神奇的萝卜丝 阅读(6) 评论(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 神奇的萝卜丝 阅读(1) 评论(0) 推荐(0) 编辑

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 神奇的萝卜丝 阅读(1) 评论(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 神奇的萝卜丝 阅读(5) 评论(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 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

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 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

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 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

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 神奇的萝卜丝 阅读(3) 评论(0) 推荐(0) 编辑

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 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

76. 最小覆盖子串
摘要:class Solution { public: map<char, int> maps, mapt; bool isContained(){ for(pair<char, int> elem : mapt){ if(elem.second > maps[elem.first]) return fa 阅读全文

posted @ 2024-09-15 20:36 神奇的萝卜丝 阅读(2) 评论(0) 推荐(0) 编辑

59. 螺旋矩阵 II
摘要:不知道一年后会成长成什么样,只感觉好难好难。有好多东西要学,源码也看不懂,项目也不会做。 class Solution { public: vector<vector<int>> generateMatrix(int n) { vector<vector<int>> vec(n, vector<in 阅读全文

posted @ 2024-09-16 22:29 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

58. 区间和(第九期模拟笔试)
摘要:中秋节摆了一天,感觉畏难情绪一直困扰着我,要好好调制状态才行。 #include<iostream> #include<vector> using namespace std; int main(){ int n = 0; cin >> n; vector<int> sum(n, 0); for(i 阅读全文

posted @ 2024-09-17 20:49 神奇的萝卜丝 阅读(8) 评论(0) 推荐(0) 编辑

44. 开发商购买土地
摘要:\ 路长且艰,任重而道远,什么时候才能成长成真正的程序员呢 #include<iostream> #include<vector> #include<climits> using namespace std; int main(){ int n, m; cin >> n >> m; vector<v 阅读全文

posted @ 2024-09-18 23:04 神奇的萝卜丝 阅读(47) 评论(0) 推荐(0) 编辑

20. 有效的括号
摘要:学习了C++ stack的使用 class Solution { public: #include<stack> bool isValid(string s) { stack<char> stk; for(int i = 0; i < s.size(); ++i){ if(s[i] == '(' | 阅读全文

posted @ 2024-09-19 11:16 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

146. LRU 缓存
摘要:\ class LRUCache { public: LRUCache(int capacity) :_capacity(capacity) {} int get(int key) { auto it = _unorderedMap.find(key); if(it != _unorderedMap 阅读全文

posted @ 2024-09-19 17:31 神奇的萝卜丝 阅读(6) 评论(0) 推荐(0) 编辑

203. 移除链表元素
摘要:老题新做 class Solution { public: ListNode* removeElements(ListNode* head, int val) { if(!head) return nullptr; if(head->val != val){ head->next = removeE 阅读全文

posted @ 2024-09-20 22:18 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

707. 设计链表
摘要:心要细,这题才能作对。 class MyLinkedList { public: MyLinkedList() :_size(0), _head(new listedNode(0)) {} int get(int index) { if(index < 0 || index >= _size) re 阅读全文

posted @ 2024-09-24 18:42 神奇的萝卜丝 阅读(5) 评论(0) 推荐(0) 编辑

206. 反转链表
摘要:class Solution { public: ListNode* reverseList(ListNode* head) { if(!head) return nullptr; ListNode* cur = head->next; if(!cur) return head; head->nex 阅读全文

posted @ 2024-09-24 18:48 神奇的萝卜丝 阅读(4) 评论(0) 推荐(0) 编辑

1 2 3 下一页
点击右上角即可分享
微信分享提示