技巧
Frontier_Setter
这个作者很懒,什么都没留下…
展开
-
[小技巧] 链表的对半划分
使用快慢指针,fast每走两步,slow走一步,当fast停下时,slow就应该停止在链表的中间。情况一:当链表有头结点head时,fast = head;slow = head;while(fast != NULL && fast->next != NULL){ fast = fast->next->next; slow = ...原创 2019-03-01 21:38:50 · 246 阅读 · 0 评论 -
[小技巧]二叉树的各种遍历
先序遍历中序遍历迭代版1:class Solution {public: vector<int> inorderTraversal(TreeNode* root) { stack<TreeNode*> S; vector<int> result; TreeNode *cur...原创 2019-03-02 21:09:54 · 216 阅读 · 0 评论 -
[小技巧]找到数集中出现次数不同的数
转载自:https://leetcode.com/problems/single-number-ii/discuss/43296/An-General-Way-to-Handle-All-this-sort-of-questions.this kind of question the key idea is design a counter that record state. the ...转载 2019-03-03 14:42:50 · 127 阅读 · 0 评论 -
[LeetCode] (medium) 373. Find K Pairs with Smallest Sums
https://leetcode.com/problems/find-k-pairs-with-smallest-sums/You are given two integer arraysnums1andnums2sorted in ascending order and an integerk.Define a pair(u,v)which consists of one...原创 2019-04-06 00:40:01 · 118 阅读 · 0 评论 -
[LeetCode] (medium) 319. Bulb Switcher
https://leetcode.com/problems/bulb-switcher/There arenbulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every thi...转载 2019-04-01 23:47:21 · 152 阅读 · 0 评论