摘要:class Solution { public: ListNode *detectCycle(ListNode *head) { ListNode* fast = head; ListNode* slow = head; while(fast && fast->next){ fast = fast-
阅读全文
摘要:明天回家喽,最近在学习的瓶颈期,感觉学的东西好难,有厌学的心理,但是我相信过了这段煎熬的时期,就好了。 class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { int na
阅读全文
摘要:class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { if(!head) return head; ListNode* dummyHead = new ListNode(0, head); ListN
阅读全文
摘要:相当于删除正数第n个节点 class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { if(!head) return head; int listLength = 0; ListNode* temp =
阅读全文
摘要:感觉自己畏难情绪好严重呀,一点都不想学新东西。 class Solution { public: ListNode* swapPairs(ListNode* head) { if(!head) return nullptr; if(!head->next) return head; ListNode
阅读全文
摘要:class Solution { public: ListNode* reverseList(ListNode* head) { if(!head) return nullptr; ListNode* cur = head->next; if(!cur) return head; head->nex
阅读全文
摘要:心要细,这题才能作对。 class MyLinkedList { public: MyLinkedList() :_size(0), _head(new listedNode(0)) {} int get(int index) { if(index < 0 || index >= _size) re
阅读全文
摘要:老题新做 class Solution { public: ListNode* removeElements(ListNode* head, int val) { if(!head) return nullptr; if(head->val != val){ head->next = removeE
阅读全文
摘要:\ class LRUCache { public: LRUCache(int capacity) :_capacity(capacity) {} int get(int key) { auto it = _unorderedMap.find(key); if(it != _unorderedMap
阅读全文
摘要:学习了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] == '(' |
阅读全文
摘要:\ 路长且艰,任重而道远,什么时候才能成长成真正的程序员呢 #include<iostream> #include<vector> #include<climits> using namespace std; int main(){ int n, m; cin >> n >> m; vector<v
阅读全文
摘要:中秋节摆了一天,感觉畏难情绪一直困扰着我,要好好调制状态才行。 #include<iostream> #include<vector> using namespace std; int main(){ int n = 0; cin >> n; vector<int> sum(n, 0); for(i
阅读全文
摘要:不知道一年后会成长成什么样,只感觉好难好难。有好多东西要学,源码也看不懂,项目也不会做。 class Solution { public: vector<vector<int>> generateMatrix(int n) { vector<vector<int>> vec(n, vector<in
阅读全文
摘要:class Solution { public: map<char, int> maps, mapt; bool isContained(){ for(pair<char, int> elem : mapt){ if(elem.second > maps[elem.first]) return fa
阅读全文
摘要:跟着别人的代码履了一遍,明天自己再重写遍。 class Solution { public: map<char, int> tstr, sstr; bool isContained(){ for(auto tchar : tstr){ if(tchar.second > sstr[tchar.fir
阅读全文
摘要:改不了C的思维 class Solution { public: int totalFruit(vector<int>& fruits) { if(fruits.size() <= 2) return fruits.size(); int left = 0, right = 0, curNum =
阅读全文
摘要:滑动窗口!! class Solution { public: int minSubArrayLen(int target, vector<int>& nums) { int left = 0, right = 0, sum = nums[0]; int minLength = INT_MAX; w
阅读全文
摘要:sort 一下 class Solution { public: vector<int> sortedSquares(vector<int>& nums) { vector<int> ret; for(int num : nums){ ret.push_back(pow(num, 2)); } so
阅读全文
摘要:c++字符串还是不太熟练 class Solution { public: bool backspaceCompare(string s, string t) { return dealString(s) == dealString(t); } private: string dealString(
阅读全文
摘要:class Solution { public: void moveZeroes(vector<int>& nums) { int head = 0, curIndex = 0; for(; curIndex < nums.size(); ++curIndex){ if(nums[curIndex]
阅读全文
摘要:class Solution { public: int removeDuplicates(vector<int>& nums) { int head = 0, curIndex = 0, target = INT_MIN; for(; curIndex < nums.size(); ++curIn
阅读全文
摘要:像个漏斗一样把元素筛出来就好了。 class Solution { public: int removeElement(vector<int>& nums, int val) { int head = 0, curIndex = 0; for(; curIndex < nums.size(); ++
阅读全文
摘要:class Solution { public: bool isPerfectSquare(int num) { int left = 0, right = num; while(left <= right){ int mid = left + (right - left) / 2; if(pow(
阅读全文
摘要:这题也是利用二分查找来计算。 首先区间是[0,x]。通过x/2的平方判断应该区间左移还是区间右移,同时值得注意的是要记录mid的平方小于x的mid值,因为比如8的平方根是2,所以平方小于x的mid要记录。 class Solution { public: int mySqrt(int x) { in
阅读全文
摘要:这题还蛮有意思的,看了下解析,分成两部分分开来求解。 左右边界都是普通的二分查找算法,重点就是当等于的时候的处理,左边界函数等于目标值的时候,要记录当前mid的值作为边界,同时区间要向左移。 反过来,右边界的话,区间要向右移动。记得记录相等时候的mid值,最后一次相等记录的值也就是这个边界值。 cl
阅读全文
摘要:class Solution { public: int search(vector<int>& nums, int target) { int head = 0, tail = nums.size() - 1; while(head <= tail){ int mid = head + (tail
阅读全文