1.python解题Leetcode? + details
2.java解题src/Solution? + details
2.C++解题CPP/Solution? + details
4.特别部分random
-
- Tencent - Machine learning Engineer
-
- Didichuxing - Statistical Analyst
-
- 字节跳动
-
- HuaWei - Machine learning Engineer
核心在于匈牙利算法
-
- 360 - Deep learning Engineer
-
- Tencent - Deep learning Engineer
-
-
Tencent - Deep learning Engineer
-
source from:http://codeforces.com/contest/474/problem/D
-
-
- 阿里 - Algorithm Engineer
-
- 携程 - Deep learning Engineer
-
- 快手2020校招
-
- 搜索二叉树
-
- 三个都是一个套路,以01背包进行拓展
-
- Almost everytime such as Alibaba、JD、Didichuxing...
-
- Hp(Hewlett-Packard) - Model Engineer
-
- 蚂蚁金服
-
- 阿里-推荐算法工程师
-
- 阿里-数据智能技术架构师
-
- source from:https://leetcode-cn.com/problems/two-sum/
-
-
左右双指针,亮点在于定义了很多提前跳出条件,在相同值跳过的条件判断中用nums[i+1]还是nums[i-1]尤为灵活
-
source from:https://leetcode-cn.com/problems/3sum/
-
-
-
这题和上面一题很类似,只是最好不要在多生产变量了,直接拿num[first]+num[last]+num[i]去和target比,而不要考虑差值是否大于0,很容易绕进去
-
source from:https://leetcode-cn.com/problems/3sum-closest/
-
-
- source from:https://leetcode-cn.com/problems/4sum/
-
- source from:https://leetcode-cn.com/problems/remove-element/
-
search-in-rotated-sorted-array
-
螺旋数组二分
-
source from:https://leetcode-cn.com/problems/search-in-rotated-sorted-array/
-
-
find-first-and-last-position-of-element-in-sorted-array
-
这个考的是二分法中的while跳出条件和left、right变化逻辑,本题是找出左右边界
-
source from:https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/
-
-
-
这题和上面这题很像,递归在for循环里面的回溯算法,把所有情况跑一遍。
画重点,求解过程中存着result 是List<List<Integer>>的,而tmp_list是list的,需要把tmp_list再裹一层new ArrayList<>(tmp_list)再进行add
-
source from:https://leetcode-cn.com/problems/combination-sum/
-
-
-
动态规划和栈的两种方法,很值得看一下
-
source from:https://leetcode-cn.com/problems/trapping-rain-water/
-
-
- source from:https://leetcode-cn.com/problems/rotate-image/
-
-
记录上次每次可跳的最远距离
-
source from:https://leetcode-cn.com/problems/jump-game/
-
-
-
旋转矩阵题型,用了余数判断位置,比较亮点
-
source from:https://leetcode-cn.com/problems/spiral-matrix-ii/
-
-
- source from:https://leetcode-cn.com/problems/sort-colors/
-
-
这题利用了python的语言机制,很有意思
-
source from::https://leetcode.com/problems/subsets/
-
-
- source from:https://leetcode-cn.com/problems/word-search/
-
- 状态二维dp+值一维dp
- 半三角dp修正
- source from:https://leetcode-cn.com/problems/palindrome-partitioning-ii/
-
-
两侧分别扫描一遍
-
source from:https://leetcode-cn.com/problems/product-of-array-except-self/
-
-
- source from:https://leetcode-cn.com/problems/move-zeroes/
-
-
抽屉原理+环+快慢指针
-
source from:https://leetcode-cn.com/problems/find-the-duplicate-number/
-
-
find-all-duplicates-in-an-array
-
和上面一样,核心是每次对abs(nums[idx])-1的处理获得nums的index很有意思
-
source from:https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/
-
-
find-all-numbers-disappeared-in-an-array
-
nums[abs(nums[idx]) - 1] = -abs(nums[abs(nums[idx]) - 1]),两个abs保证了所有存在的idx都被置负了
-
source from:https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/
-
-
-
理解一下,出现次数最多的那个字母(出现次数-1)x时间窗口及为最小次数,剩余要考虑的是都为最多次数的字母数
-
source from:https://leetcode-cn.com/problems/task-scheduler/
-
-
- source from:https://leetcode-cn.com/problems/maximum-swap/
-
-
这道题的难点在于耗时,贪心算法即可,田忌赛马,可以看下
-
source from:https://leetcode-cn.com/problems/advantage-shuffle/
-
-
- 前缀和技巧题,主要是要知道a-b能被k整除,那么有a%k==b%k
- source from:https://leetcode-cn.com/problems/subarray-sums-divisible-by-k/
-
- source from:https://leetcode-cn.com/problems/height-checker/
-
- 分N种情况讨论状态转移矩阵。复杂:1、转移矩阵,2、初始化逻辑
- source from:https://leetcode-cn.com/problems/regular-expression-matching/
-
- source from:https://leetcode-cn.com/problems/jump-game-ii/
-
-
中心展开,从中间值往两边展开,判断展开终止点的长度
-
source from:https://leetcode-cn.com/problems/longest-palindromic-substring/
-
-
-
简单递归
-
source from:https://leetcode-cn.com/problems/maximum-subarray/
-
-
- source from:https://leetcode-cn.com/problems/unique-paths/
-
-
最优路径下的dp
-
source from:https://leetcode-cn.com/problems/unique-paths-ii/
-
-
-
非常基础简单的动态规划问题,适合理解动态规范的想法
-
source from:https://leetcode-cn.com/problems/minimum-path-sum/
-
-
- dp
- source from:https://leetcode-cn.com/problems/gray-code/
-
-
状态转移方程式dp[i] = dp[i-1]+dp[i-2],复杂在什么时候加前项什么时候加后项,什么时候加两项,0的位置的考虑
-
source from:https://leetcode-cn.com/problems/decode-ways/
-
-
- 和文本编辑距离的思路很像
- source from:https://leetcode-cn.com/problems/distinct-subsequences/
-
- source from:https://leetcode-cn.com/problems/triangle/
-
-
第一轮用的traceback,时间复杂度是n的n次方,扑gai;然后我想了下,既然可以考虑回溯,为什么不能递归,其实只要把方程:flag[j] = flag[i]+s[i:j] in wordDict 这个想到就行,这个算是是像加限制性条件的dp,比如20届拼多多校招,多多鸡砍树问题
-
source from:https://leetcode-cn.com/problems/word-break/
-
-
-
需要存一个max和min,来做条件判断
-
source from:https://leetcode-cn.com/problems/maximum-product-subarray/
-
-
-
反向递归
-
source from:https://leetcode-cn.com/problems/dungeon-game/
-
-
-
dp算法很经典的一道题
-
source from:https://leetcode-cn.com/problems/house-robber/
-
-
- source from:https://leetcode-cn.com/problems/maximal-square/
-
- source from:https://leetcode-cn.com/problems/ugly-number-ii/
-
-
双循环的dp,同样的思路python会超时,Java不会
-
source from:https://leetcode-cn.com/problems/perfect-squares/
-
-
longest-increasing-subsequence
-
dp和递归理解的好题目,值得看
-
source from:https://leetcode-cn.com/problems/longest-increasing-subsequence/
-
-
best-time-to-buy-and-sell-stock-with-cooldown
-
dp的高难题,代码中带完整带解题方法
-
source from:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/
-
-
-
dp的超高难题,代码中带完整带解题方法
-
source from:https://leetcode-cn.com/problems/burst-balloons/
-
-
-
斐波纳切动态规划
-
source from:https://leetcode-cn.com/problems/coin-change/
-
-
- source from:https://leetcode-cn.com/problems/counting-bits/
-
- source from:https://leetcode-cn.com/problems/integer-break/
-
-
01背包
-
source from:https://leetcode-cn.com/problems/ones-and-zeroes/
-
-
-
01背包问题,这题主要考虑提前跳出条件
-
source from:https://leetcode-cn.com/problems/partition-equal-subset-sum/
-
-
-
01背包+递归逻辑
-
source from:https://leetcode-cn.com/problems/target-sum/
-
-
longest-palindromic-subsequence
- 子序列通用双循环dp,这次因为涉及反推,所以用的是倒推法
- source from:https://leetcode-cn.com/problems/longest-palindromic-subsequence/
-
-
回文子串问题
-
source from:https://leetcode-cn.com/problems/palindromic-substrings/
-
-
Partition to K Equal Sum Subsets
-
依旧是递归,区别在递归逻辑在for循环中,相当于并发了n条处理逻辑,有点像树展开
-
source from:https://leetcode-cn.com/problems/partition-to-k-equal-sum-subsets/
-
-
-
核心在于bitmap+dp,与198题类似
-
source from:https://leetcode-cn.com/problems/delete-and-earn/
-
-
length-of-longest-fibonacci-subsequence
- 字典进行递归,以后[i,j]作为递归条件判断
- source from:https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/
-
valid-permutations-for-di-sequence
-
爱奇艺2020届校招
-
source from:https://leetcode-cn.com/problems/valid-permutations-for-di-sequence/
-
-
-
贪心算法概念的比较好理解的一道题
-
source from:https://leetcode-cn.com/problems/video-stitching/
-
-
-
hashmap+简单dp
-
source from:https://leetcode-cn.com/problems/longest-string-chain/
-
-
-
最简单的dp
-
source from:https://leetcode-cn.com/problems/n-th-tribonacci-number/
-
-
-
子序列双循环dp
-
source from:https://leetcode-cn.com/problems/longest-common-subsequence/
-
-
longest-arithmetic-subsequence-of-given-difference
-
记录状态,和跳跃游戏1一样
-
source from:https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference/
-
-
-
二叉树中序遍历三种写法
-
source from:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
-
-
binary-tree-level-order-traversal
-
二叉树层序遍历,利用了队列先进先出的性质
-
source from:https://leetcode-cn.com/problems/binary-tree-level-order-traversal/
-
-
-
二叉树深度计算,利用了递归性质
-
source from:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/
-
-
-
二叉树合并,利用了递归性质
-
source from:https://leetcode-cn.com/problems/merge-two-binary-trees/
-
-
-
结点之间的最大距离,和104题的深度一样
-
source from:https://leetcode-cn.com/problems/diameter-of-binary-tree/
-
-
-
先遍历右子树的中序遍历,面试之前一定要看,易于理解递归在二叉树中的应用
-
source from:https://leetcode-cn.com/problems/convert-bst-to-greater-tree/
-
-
-
反转树,相互对称
-
source from:https://leetcode-cn.com/problems/invert-binary-tree/
-
-
-
tire 字典实现
-
source from:https://leetcode-cn.com/problems/implement-trie-prefix-tree/
-
-
construct-binary-tree-from-preorder-and-inorder-traversal
-
360面试题,真有意思
-
source from:https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
-
-
serialize-and-deserialize-binary-tree
-
二叉树-->list//list-->二叉树
-
source from:https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/
-
-
lowest-common-ancestor-of-a-binary-tree
-
left if right is None else right if left is None else root
-
source from:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/
-
-
lowest-common-ancestor-of-a-binary-search-tree
-
和上面一题一摸一样
-
source from:https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
-
-
-
动态规划
-
source from:https://leetcode-cn.com/problems/unique-binary-search-trees/
-
-
-
层次遍历
-
source from:https://leetcode-cn.com/problems/symmetric-tree/
-
-
-
搜索二叉树的左支<结点<右支,正好可以用中序遍历比较
-
source from:https://leetcode-cn.com/problems/validate-binary-search-tree/
-
-
-
类似104题、543题这种递归的方式
-
source from:https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/
-
-
-
dfs+两数之和
-
source from:https://leetcode-cn.com/problems/path-sum-iii/
-
-
-
和unique-binary-search-trees这题思路一样,不同的是,unique-binary-search-trees用的是dp,本题用的是递归,核心和之前一样,[start,i]作为左树去递归,node(i)作为根,[i+1,end]作为右树去递归
-
source from:https://leetcode-cn.com/problems/unique-binary-search-trees-ii/
-
-
-
层序遍历改写
-
source from:https://leetcode-cn.com/problems/same-tree/
-
-
binary-tree-zigzag-level-order-traversal
-
层序遍历改写
-
source from:https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/
-
-
-
BST+中序遍历的结果是有序的,
self.ans.append(root)
直接加结点,而非加值了 -
source from:https://leetcode-cn.com/problems/recover-binary-search-tree/
-
-
-
基于树结构+动态规划,可谓是花哨到极点了
-
source from:https://leetcode-cn.com/problems/house-robber-iii/
-
-
binary-tree-level-order-traversal-ii
-
层次遍历翻版
-
source from:https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/
-
-
convert-sorted-array-to-binary-search-tree
-
有序数组-->平衡二叉树:二分查找+递归
-
source from:https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/
-
-
-
判断是否为平衡二叉树,利用的是dfs+maximum-depth-of-binary-tree二叉树深度计算的方法
-
source from:https://leetcode-cn.com/problems/balanced-binary-tree/
-
-
-
source from:https://leetcode-cn.com/problems/path-sum/
-
上面这两题在return的时候都做了是否是根结点的判断:
left if root.right is None else right if root.left is None else left or right
-
-
-
dfs
-
source from:https://leetcode-cn.com/problems/path-sum-ii/
-
-
flatten-binary-tree-to-linked-list
-
有点技巧性
-
source from:https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list/
-
-
populating-next-right-pointers-in-each-node
-
跨结点直接的指向关系由root.next is not None产生
-
source from:https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node/
-
-
populating-next-right-pointers-in-each-node-ii
-
与上一次递归不同,这一次因为不知道root对应的下一层是否有空结点,所以针对上一层的判断结果进行迭代
-
source from:https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node-ii/
-
-
-
dfs
-
source from:https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/
-
-
binary-tree-preorder-traversal
-
前序遍历迭代版,技巧就是queue进栈的策略是先右后左,因为前序遍历是中左右,进栈越早出栈越晚
-
source from:https://leetcode-cn.com/problems/binary-tree-preorder-traversal/
-
-
binary-tree-postorder-traversal
-
巧妙的解法:宽度搜索+逆序出栈==后序输出
。另外,这份代码在node = queue.pop()
-->node = queue.pop(0)
,加个0就是层序遍历 -
source from:https://leetcode-cn.com/problems/binary-tree-postorder-traversal/
-
以上两题加binary-tree-inorder-traversal都是迭代的解法,前序中序写的比较中规中矩,后序写的真的是惊艳
-
-
层序遍历
-
source from:https://leetcode-cn.com/problems/binary-tree-right-side-view/
-
-
add-and-search-word-data-structure-design
-
Tire树很经典的一道题
-
source from::https://leetcode-cn.com/problems/add-and-search-word-data-structure-design/
-
-
-
借鉴了上一题中的generation的写法,我觉得非常适合业务中真实使用
-
source from:https://leetcode-cn.com/problems/binary-search-tree-iterator/
-
-
-
dfs
-
source from:https://leetcode-cn.com/problems/binary-tree-paths/
-
-
-
限制性条件下的二叉树遍历计算查找,迭代要比计算更加高效
-
source from:https://leetcode-cn.com/problems/sum-of-left-leaves/
-
-
-
前序遍历保存,二叉搜索树的中序遍历为升序列,两则可以恢复原树
-
source from:https://leetcode-cn.com/problems/serialize-and-deserialize-bst/
-
-
-
看子节点的是否为None,分情况讨论
-
source from:https://leetcode-cn.com/problems/delete-node-in-a-bst/
-
-
find-mode-in-binary-search-tree
-
直接遍历统计
-
source from:https://leetcode-cn.com/problems/find-mode-in-binary-search-tree/
-
-
-
递归求解,好题目
-
source from:https://leetcode-cn.com/problems/subtree-of-another-tree/
-
-
-
和binary-tree-tilt一样,计算每个结点的子树之和。
-
source from:https://leetcode-cn.com/problems/most-frequent-subtree-sum/
-
-
-
递归直接修改树的实现,爬楼梯的翻版
-
source from:https://leetcode-cn.com/problems/add-one-row-to-tree/
-
-
-
套路总结
-
source from:https://leetcode-cn.com/problems/find-duplicate-subtrees/
-
-
-
如果接一个
root = self.trimBST
相当于对结点做一个覆盖,也就是直接修改树 -
source from:https://leetcode-cn.com/problems/trim-a-binary-search-tree/
-
-
second-minimum-node-in-a-binary-tree
-
log(h)的跳出条件的递归写法
-
source from:https://leetcode-cn.com/problems/second-minimum-node-in-a-binary-tree/
-
-
-
逻辑理解的递归
-
source from:https://leetcode-cn.com/problems/longest-univalue-path/
-
-
-
先递归到底层,然后在判断是否可以被修剪,修剪条件就是
root.val == 0 and not root.left and not root.right:
-
source from:https://leetcode-cn.com/problems/binary-tree-pruning/
-
-
smallest-subtree-with-all-the-deepest-nodes
-
构造了数据对[root,depth],用depth判断深度,用root返回depth对应的root
-
source from:https://leetcode-cn.com/problems/smallest-subtree-with-all-the-deepest-nodes/
-
-
all-possible-full-binary-trees
-
基于树的动态规划,考前必看
-
source from:https://leetcode-cn.com/problems/all-possible-full-binary-trees/
-
-
check-completeness-of-a-binary-tree
-
层次遍历,出现空之后不能再出现结点
-
source from:https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree/
-
-
distribute-coins-in-binary-tree
-
金币题,题目有点难理解,算得是每个结点的多余量,这题和jump-game神似
-
source from:https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/
-
-
-
这题是结合了父结点+子节点递归,利用depth保存层数,parent保存子结点对应的父结点
-
source from:https://leetcode-cn.com/problems/cousins-in-binary-tree/
-
-
sum-of-root-to-leaf-binary-numbers
-
^
在python里面是抑或,不是次方 -
source from:https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers/
-
-
delete-nodes-and-return-forest
-
复杂的dfs,在dfs的过程中对树进行修正和保存,有点难
-
source from:https://leetcode-cn.com/problems/delete-nodes-and-return-forest/
-
-
recover-a-tree-from-preorder-traversal
-
hashmap存结点,每次更新
-
source from:https://leetcode-cn.com/problems/recover-a-tree-from-preorder-traversal/
-
-
- 回溯/DFS
- source from:https://leetcode-cn.com/problems/number-of-islands/
-
- dfs
- source from:https://leetcode-cn.com/problems/generate-parentheses/
-
- dfs,组合题型1
- source from:https://leetcode-cn.com/problems/combination-sum/
-
- dfs,组合题型2,index>start保证了双跳跃逻辑,很nice
- source from:https://leetcode-cn.com/problems/combination-sum-ii/
-
- dfs,全排列升级版
- source from:https://leetcode-cn.com/problems/subsets-ii/
-
- dfs,组合题型3
- source from:https://leetcode-cn.com/problems/combination-sum-iii/
-
- dfs,当迭代轮数超过一次完整循环的值的时候,直接跳过
- source from:https://leetcode-cn.com/problems/permutation-sequence/
-
- source from:https://leetcode-cn.com/problems/combinations/
-
- dfs
- source from:https://leetcode-cn.com/problems/coin-change-2/
-
maximum-length-of-a-concatenated-string-with-unique-characters
-
maximum-length-of-a-concatenated-string-with-unique-characters
-
evaluate-reverse-polish-notation
-
栈,亮点在python 中对负数取整数部分如何操作
-
source from:https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/
-
-
-
辅助栈,不需要排序,仅需要知道当前最小即可
-
source from:https://leetcode-cn.com/problems/min-stack/
-
-
-
出入栈题,有点难想到
-
source from:https://leetcode-cn.com/problems/decode-string/
-
-
-
位运算
-
source from:https://leetcode-cn.com/problems/divide-two-integers/
-
-
-
最简单的递归,和快排,斐波纳切数列一致的写法
-
source from:https://leetcode-cn.com/problems/powx-n/
-
-
-
这题其实可以从右上角开始查找,会更快
-
source from::https://leetcode.com/problems/search-a-2d-matrix-ii/
-
-
-
二分搜索,亮点在分组最大和变成了原数组的
[max(原数组),sum(原数组))
-
source from:https://leetcode-cn.com/problems/split-array-largest-sum/
-
-
- source from:https://leetcode-cn.com/problems/binary-search/
-
LetterCombinationsofaPhoneNumber
-
这题用了dp和递归两种方法,dp更好理解也很Pythonic,递归则更加通用
-
盖题递归位置在循环中,很有意思
-
source from:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
-
-
-
递归
-
source from:https://leetcode-cn.com/problems/permutations/
-
-
-
简单的回溯算法
-
source from:https://leetcode-cn.com/problems/permutations-ii/
-
-
-
地址和值;已经用ansValue用的是内存地址,时刻在变,所以要new ArrayList(ansValue)固定值使其不变
-
回溯的剔除;
-
source from:https://leetcode-cn.com/problems/palindrome-partitioning/
-
-
remove-nth-node-from-end-of-list
-
链表很经典的一道题
-
source from::https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/
-
-
-
递归算法,讲的很详细,递归复习专用
-
该题递归在函数中间位置,很有意思
-
source from:https://leetcode-cn.com/problems/swap-nodes-in-pairs/
-
-
-
协助理解链表里面的head = head, head.next = head.next.next
-
source from:https://leetcode-cn.com/problems/remove-linked-list-elements/
-
-
-
递归在中间,简单题,对比上面的24题可以对比着看
-
source from:https://leetcode-cn.com/problems/reverse-linked-list/
-
-
- 翻转链表用的是迭代,参考206题reverse-linked-list
- 交换参考的是24题Swap Nodes in Pairs
- source from:https://leetcode-cn.com/problems/reverse-nodes-in-k-group/
- 深入理解地址和值
-
- 快慢指针,类似题型find-the-duplicate-number
- source from:https://leetcode-cn.com/problems/linked-list-cycle/
-
- 快慢指针,类似题型find-the-duplicate-number
- source from:https://leetcode-cn.com/problems/linked-list-cycle-ii/
-
intersection-of-two-linked-lists
- source from:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
- 短链表+长链表<-->长链表+短链表,同等初始的结尾即为交点
-
- source from:https://leetcode-cn.com/problems/sort-list/
- 并归排序+链表
-
- source from:https://leetcode-cn.com/problems/merge-k-sorted-lists/
- 和上一个很像,并归排序+链表
- 快排按照标值二分,小的在前大的在后,而归并则是按照下标二分,再分别对两个部分归并排序,先分后和,在和的过程中排序
-
- source from:https://leetcode-cn.com/problems/rotate-list/
-
remove-duplicates-from-sorted-list-ii
- source from:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/
- 建立一个哨兵指针,每次对比cur和cur.next的val是否一致
-
remove-duplicates-from-sorted-list
- source from:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
- 上面一条的简单版本
-
- source from:https://leetcode-cn.com/problems/partition-list/
-
- source from:https://leetcode-cn.com/problems/reverse-linked-list-ii/
- prev.next为反转后的尾结点,正好可以接剩余结点,非常精彩
-
- source from:https://leetcode-cn.com/problems/reorder-list/
- 反转链表reverse-linked-list
-
- source from:https://leetcode-cn.com/problems/insertion-sort-list/
- 这题和remove-duplicates-from-sorted-list-ii类似,需要不停的从head结点找到比当前结点.next.val要小的结点位置
- 链表删结点方法
-
- source from:https://leetcode-cn.com/problems/delete-node-in-a-linked-list/
- 一行但是非常技巧
-
- source from:https://leetcode-cn.com/problems/add-two-numbers-ii/
- 双栈+链表
-
remove-zero-sum-consecutive-nodes-from-linked-list
- source from:https://leetcode-cn.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/
- 前缀和+递归,面试前必看
-
kth-largest-element-in-an-array
-
加速的地方在于,维护好容量为k的小根堆之后,只需要保证根堆的根结点最小即可。
min_heap(k_min, k, 0)
-
source from:https://leetcode-cn.com/problems/kth-largest-element-in-an-array/
-
-
-
双端队列题目,用队列保留一个递减序列
-
source from:https://leetcode-cn.com/problems/sliding-window-maximum/
-
-
-
求最大:小根堆;求最小:大根堆。因为只需要保证最大最小的k个值在堆内即可,无需遍历堆。 根堆输出的时候,每次交换根堆根结点到最后,小根堆的化,数组越靠后越小,相当于降序排列;大根堆的话,数组越往后越大,相当于升序排列。
-
source from:https://leetcode-cn.com/problems/top-k-frequent-elements/
-
-
-
数组当做双指针的一种方式
-
source from:https://leetcode-cn.com/problems/summary-ranges/
-
-
-
双指针
-
source from:https://leetcode-cn.com/problems/boats-to-save-people/
-
-
-
双指针
-
source from:https://leetcode-cn.com/problems/fruit-into-baskets/
-
-
-
双指针+滑动窗口,模板要记得
-
source from:https://leetcode-cn.com/problems/minimum-window-substring/
-
-
-
双指针+滑动窗口,模板要记得
-
source from:https://leetcode-cn.com/problems/is-subsequence/
-
-
-
子集问题,双指针
-
source from:https://leetcode-cn.com/problems/minimum-size-subarray-sum/
-
-
longest-chunked-palindrome-decomposition
-
回文问题,双指针
-
source from:https://leetcode-cn.com/problems/longest-chunked-palindrome-decomposition/
-
-
-
回文问题,双指针
-
source from:https://leetcode-cn.com/problems/shortest-palindrome/
-
-
-
区间边界解决重复,双指针
-
source from:https://leetcode-cn.com/problems/subarray-product-less-than-k/
-
-
replace-the-substring-for-balanced-string
-
最优子串,双指针
-
source from:https://leetcode-cn.com/problems/replace-the-substring-for-balanced-string/
-
-
- source from:https://leetcode-cn.com/problems/detect-capital/
-
- source from:https://leetcode-cn.com/problems/goat-latin/
-
-
有点冒泡排序的意思
-
source from:https://leetcode-cn.com/problems/orderly-queue/
-
-
-
python用了最简单的递归表示,把结果表示出来再做,比较慢,所以加了@functools.lru_cache(maxsize=128, typed=False)对结果进行缓存
-
source from:https://leetcode-cn.com/problems/k-th-symbol-in-grammar/
-
-
-
直接罗列全情况,排除一下就行
-
source from:https://leetcode-cn.com/problems/valid-tic-tac-toe-state/
-
-
-
蓄水池抽烟,randint(0,cnt)控制了每次被抛弃的概率为1/(1+cnt)
-
source from:https://leetcode-cn.com/problems/random-pick-index/
-
-
- source from:https://leetcode-cn.com/problems/ugly-number/
-
- source from:https://leetcode-cn.com/problems/reach-a-number/
-
-
逻辑鬼才的题目
-
source from:https://leetcode-cn.com/problems/chalkboard-xor-game/
-
-
-
任给三点,三角形面积等于abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2
-
source from:https://leetcode-cn.com/problems/largest-triangle-area/
-
-
-
(n-m)(n+m+1)=2N,a=n-m,b=n+m+1,a+b=2n+1,b-a=2m+1,所以a*b=2N,a,b一奇一偶
-
source from:https://leetcode-cn.com/problems/consecutive-numbers-sum/
-
-
-
透视图角度
-
source from:https://leetcode-cn.com/problems/surface-area-of-3d-shapes/
-
-
greatest-common-divisor-of-strings
-
gcd,最大公约数;辗转相除法复习
-
source from:https://leetcode-cn.com/problems/greatest-common-divisor-of-strings/
-
-
- 素数+回文
- source from:https://leetcode-cn.com/problems/prime-palindrome/
-
- 罗列情况
- source from:https://leetcode-cn.com/problems/find-the-closest-palindrome/
-
- 2N-2>N
- source from:https://leetcode-cn.com/problems/repeated-substring-pattern/
-
- 平方数之和
- 二分查找
- source from:https://leetcode-cn.com/problems/sum-of-square-numbers/
-
-
这题有数学解法和位解法两种,都很值得看一下
-
source from:https://leetcode.com/problems/single-number/description/
-
-
-
知识点1:设计一个逻辑运算,使满足存在两个变量a和b,当遍历nums的时候,对于重复元素x,第一次碰到x的时候,我们会将x赋给a,第二次碰到后再赋给b,第三次则全量抵消
-
知识点2:x&~x=0
-
source from:https://leetcode-cn.com/problems/single-number-ii/
-
-
- source from:https://leetcode-cn.com/problems/reverse-bits/
-
-
滑动窗口去解决字符串匹配问题
-
source from:https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/
-
-
substring-with-concatenation-of-all-words
- hash对比
- source from:https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/
-
- source from:https://leetcode-cn.com/problems/gas-station/
-
-
转转2020届校招
-
分发糖果,左右各扫一遍取max
-
source from:https://leetcode-cn.com/problems/candy/
-
-
queue-reconstruction-by-height
-
原题说的是前面大于等于当前身高的,所以插矮个子不会影响排序
-
source from:https://leetcode-cn.com/problems/queue-reconstruction-by-height/
-
-
-
分桶,亮点在于分N+1个桶,保证一定有一个空桶,空桶的存在保证最大间隔在桶之间,不需要再去比桶内值
-
source from:https://leetcode-cn.com/problems/maximum-gap/
-
-
-
规律题,数学归纳
-
source from:https://leetcode-cn.com/problems/nim-game/
-
-
-
字典排序,用了python特性,也同时整理基础概念,值得去看
-
source from:https://leetcode-cn.com/problems/lexicographical-numbers/
-
-
-
such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false,其中只要保证固定住最小和最大,不断降低最小值的下限,使得比最小值要大的值可以尽可能的接近最小值,从而更容易找到比接近最小值的值
-
source from:https://leetcode-cn.com/problems/increasing-triplet-subsequence/
-
-
- source from:https://leetcode-cn.com/problems/relative-ranks/
-
-
这题技巧题,理解sorted中的cmp和key的作用,key是sorted元素判断依据的接受入口,而接收值需要调用functools中的cmp_to_key进行包装,python2不用这么复杂
-
source from:https://leetcode-cn.com/problems/largest-number/
-
-
- source from:https://leetcode-cn.com/problems/lru-cache/