代码改变世界

随笔分类 -  LeetCode conclusion

Data structure - Sort & quick sort 小结及leetcode相关题目

2023-10-21 02:48 by Johnson_强生仔仔, 51 阅读, 收藏, 编辑
摘要: Sort 主要有以下几种常见的sort, 面试中最有可能考的是quick sort, 关于k largest or 什么相关的。 Bubble sort Insertion sort Merge sort Quicksort Selection sort Counting sort Bucket s 阅读全文

quickSort use two pointers to decrease Time into O(n * lgn ) or O(n)

2021-06-28 08:45 by Johnson_强生仔仔, 44 阅读, 收藏, 编辑
摘要: Quicksort, 选取pivot, 然后有两个指针, left = 0, right = n - 1, left 不停右移找到nums[left] > pivot, right 不停左移找到nums[right] <= pivot直到left >= right, 停止,那么这时候再recursi 阅读全文

Prefix Sum & Dictionary Time and Space O(n) for -- Find a number of continuous subarrays/submatrices/tree paths that sum to target

2021-06-18 20:31 by Johnson_强生仔仔, 47 阅读, 收藏, 编辑
摘要: Prefix sum, 参考这个solution, 讲解的很清楚。 . What is prefix sum Prefix sum is a sum of the current value with all previous elements starting from the beginning 阅读全文

Morris Traversal_ O(1) space to change binary tree to linked list

2021-06-18 19:04 by Johnson_强生仔仔, 48 阅读, 收藏, 编辑
摘要: 问题可以参考[LeetCode] 114. Flatten Binary Tree to Linked List_Medium tag: DFS, 这个Morris Traversal能够解决follow up,怎么样用 space O(1) 来去解决这个问题。参考这个题目的solution的app 阅读全文

[LeetCode] 系统刷题9_Backtracking

2021-06-12 10:14 by Johnson_强生仔仔, 54 阅读, 收藏, 编辑
摘要: 有待总结。 Binary Search: 633, Sum of Square Numbers 475, Heaters 744, Find Smallest Letter Greater than target(LC submissions from original session) 427?? 阅读全文

[LeetCode] 系统刷题8_Data Structure

2019-05-13 04:21 by Johnson_强生仔仔, 286 阅读, 收藏, 编辑
摘要: Linear data structure Queue used for BFS most of time O(1) for push O(1) for Pop O(1) for Top Stack . 得到第一个左边比该点小的,第一个右边比该点小的 => strict increasing sta 阅读全文

[LeetCode] 系统刷题7_Array & numbers & string

2019-05-09 11:22 by Johnson_强生仔仔, 346 阅读, 收藏, 编辑
摘要: 1. 2 D Array 如果是在左上到右下的斜线的话,在同一条斜线上的x - y 相等, (x, y) 是该点的坐标 如果是在左下到右上的斜线的话,在同一条斜线上的x + y 相等, (x, y) 是该点的坐标 ex. [(1, 1), (1, 2), (1, 3)] [(2, 1), (2, 2 阅读全文

[LeetCode] 系统刷题6_Linked List

2019-04-30 01:07 by Johnson_强生仔仔, 293 阅读, 收藏, 编辑
摘要: 1. Dummy Node [LeetCode] 83. Remove Duplicates from Sorted List_Easy tag: Linked List [LeetCode] 82. Remove Duplicates from Sorted List II_Medium tag: 阅读全文

[LeetCode] 系统刷题5_Dynamic Programming

2019-04-30 00:06 by Johnson_强生仔仔, 328 阅读, 收藏, 编辑
摘要: Dynamic Programming 实际上是[LeetCode] 系统刷题4_Binary Tree & Divide and Conquer的基础上,加上记忆化的过程。就是说,如果这个题目实际上是类似于Divide and conquer或者说是DFS,但是在计算过程中有很多重复计算同样的过程 阅读全文

[LeetCode] 系统刷题4_Binary Tree & Divide and Conquer

2019-04-18 09:14 by Johnson_强生仔仔, 335 阅读, 收藏, 编辑
摘要: The most important : [LeetCode] questions conclustion_BFS, DFS 参考[LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal 可以对binary tree进 阅读全文

[LeetCode] 系统刷题2_Binary search

2019-04-16 10:27 by Johnson_强生仔仔, 257 阅读, 收藏, 编辑
摘要: 可以参考 [LeetCode] questions conclusion_ Binary Search 阅读全文

[LeetCode] 系统刷题3_排列组合/backtracking

2019-04-11 10:23 by Johnson_强生仔仔, 318 阅读, 收藏, 编辑
摘要: 适用范围: 几乎所有搜索问题 什么时候输出 哪些情况需要跳过 Python library import itertools itertools.product('ABC', repeat = 2) 3 * 3 = 9 list(itertools.product('ABC', repeat = 2 阅读全文

[LeetCode] 系统刷题1_代码风格及边界

2019-02-10 10:58 by Johnson_强生仔仔, 626 阅读, 收藏, 编辑
摘要: 代码风格 不说自己不清楚的算法,比如KMP,如果解释不清楚或者写不出来的算法建议不提 注意代码的缩进以及空格的合理运用,使得代码看起来比较整洁有条理 注意边界的条件以及越界 误区: 算法想出来还仅仅不够 算法写出来也还不够 试着从面试官的角度来思考: coding风格(缩进,括号,变量名) codi 阅读全文

[LeetCode] questions conclusion_ Binary Search

2018-08-29 06:49 by Johnson_强生仔仔, 343 阅读, 收藏, 编辑
摘要: Binary Search T(n) = T(n/2) + O(1) => T(n) = O(lg n) proof: 如果能用iterable , 就用while loop, 可以防止用recursion的时候stack overflow( process in Linux is 8Mb), st 阅读全文

[LeetCode] All questions numbers conclusion 所有题目题号

2018-08-07 00:50 by Johnson_强生仔仔, 520 阅读, 收藏, 编辑
摘要: Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, DFS LeetCode questions conclustion_Path in Tree [L 阅读全文

[LeetCode] questions conclusion_ Dynamic Programming

2018-08-06 23:49 by Johnson_强生仔仔, 337 阅读, 收藏, 编辑
摘要: Questions: [LeetCode] 198. House Robber _Easy tag: Dynamic Programming [LeetCode] 221. Maximal Square _ Medium Tag: Dynamic Programming [LeetCode] 62. 阅读全文

[LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal

2018-07-22 00:03 by Johnson_强生仔仔, 450 阅读, 收藏, 编辑
摘要: Pre: node 先, Inorder: node in, Postorder: node 最后 PreOrder Inorder PostOrder node-> left -> right left -> node ->right left -> right ->node Recursive 阅读全文

[LeetCode] questions conclustion_Path in Tree

2018-07-18 00:29 by Johnson_强生仔仔, 353 阅读, 收藏, 编辑
摘要: Path in Tree: [LeetCode] 112. Path Sum_Easy tag: DFS input: root, target, return True if exists sum(root-> leaf) == target else False 1 [LeetCode] 257 阅读全文

[LeetCode] questions conclustion_BFS, DFS

2018-07-17 01:37 by Johnson_强生仔仔, 538 阅读, 收藏, 编辑
摘要: BFS, DFS 的题目总结. Directed graph: Directed Graph Loop detection and if not have, path to print all path. Morris Traversal_ O(1) space to change binary t 阅读全文
点击右上角即可分享
微信分享提示