代码改变世界

[LeetCode] 208. Implement Trie (Prefix Tree)_Medium tag: Trie

2021-06-29 05:20 by Johnson_强生仔仔, 34 阅读, 0 推荐, 收藏, 编辑
摘要:A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are va 阅读全文

[LeetCode] 703. Kth Largest Element in a Stream_Easy tag: Heap

2021-06-28 10:41 by Johnson_强生仔仔, 21 阅读, 0 推荐, 收藏, 编辑
摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. 阅读全文

[LeetCode] 347. Top K Frequent Elements_Medium tag: Array, Heap, quickSort

2021-06-28 09:51 by Johnson_强生仔仔, 46 阅读, 0 推荐, 收藏, 编辑
摘要:Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [1 阅读全文

[LeetCode] 215. Kth Largest Element in an Array_Medium tag: sort, Heap, quickSort

2021-06-28 09:04 by Johnson_强生仔仔, 42 阅读, 0 推荐, 收藏, 编辑
摘要:Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order 阅读全文

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

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

[LeetCode] 560.Subarray Sum Equals K_Medium tag: Array, Subarray, prefix Sum

2021-06-18 20:36 by Johnson_强生仔仔, 30 阅读, 0 推荐, 收藏, 编辑
摘要:Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k. Example 1: Input: nums = [1,1 阅读全文

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_强生仔仔, 40 阅读, 0 推荐, 收藏, 编辑
摘要: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_强生仔仔, 46 阅读, 0 推荐, 收藏, 编辑
摘要:问题可以参考[LeetCode] 114. Flatten Binary Tree to Linked List_Medium tag: DFS, 这个Morris Traversal能够解决follow up,怎么样用 space O(1) 来去解决这个问题。参考这个题目的solution的app 阅读全文

[LeetCode] 1485. Clone Binary Tree With Random Pointer_ Medium tag: BFS, DFS

2021-06-16 09:21 by Johnson_强生仔仔, 84 阅读, 0 推荐, 收藏, 编辑
摘要:A binary tree is given such that each node contains an additional random pointer which could point to any node in the tree or null. Return a deep copy 阅读全文

[LeetCode] 系统刷题9_Backtracking

2021-06-12 10:14 by Johnson_强生仔仔, 47 阅读, 0 推荐, 收藏, 编辑
摘要:有待总结。 Binary Search: 633, Sum of Square Numbers 475, Heaters 744, Find Smallest Letter Greater than target(LC submissions from original session) 427?? 阅读全文
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 39 下一页