- 博客(7)
- 收藏
- 关注
原创 Leetcode 刷题笔记 (二叉树)
Leetcode 刷题笔记 (二叉树)二叉树Leetcode 刷题笔记 (二叉树)idea二叉递归模板543. 二叉树的直径 (easy)124. 二叉树中的最大路径和(hard) 同543199. 二叉树的右视图(medium)337. 打家劫舍 III(medium) dfs + dpideadfs递归搜索二叉二叉递归模板def dfs (node): if not node: return 0 left = dfs(node.left)
2022-05-06 16:06:05 550
原创 Leetcode 刷题笔记 (搜索)
Leetcode 刷题笔记 (搜索)ideadfs 递归dfs + 栈bfs695. 岛屿的最大面积(medium)https://leetcode-cn.com/problems/max-area-of-island/dfs 递归class Solution: def dfs(self, grid, cur_i, cur_j): if cur_j<0 or cur_i<0 or cur_i == len(grid) or cur_j == len(g
2022-04-19 14:02:15 376
原创 Leetcode 刷题笔记 (sort)
Leetcode 刷题笔记 Sortidea:912. Sort an Array (medium) (quicksort)idea:quicksort: 随机取pivot 可以避免最坏情况912. Sort an Array (medium) (quicksort)https://leetcode.com/problems/sort-an-array/class Solution: def sortArray(self, nums: List[int]) -> List[int]:
2022-03-05 14:35:28 312
原创 Leetcode 刷题笔记 (rotated sorted Array) (binary search)
Leetcode 刷题笔记 binary search(rotated sorted Array)idea:(rotated sorted Array) 81. Search in Rotated Sorted Array II (medium)(rotated sorted Array) 154. Find Minimum in Rotated Sorted Array II (hard)(rotated sorted Array) 33. Search in Rotated Sorted Array(m
2022-03-03 15:31:00 357
原创 Leetcode 刷题笔记 (binary search)
Leetcode 刷题笔记 binary search二分法34. Find First and Last Position of Element in Sorted Array(medium)69. Sqrt(x) (easy)二分法l = 0, r = 0, mid = (l + r) // 2二分法就是首尾双指针 (每轮移位为一个区间)nums[mid] > target >>> r = mid - 1;else: l = mid + 1时间复杂度 O(logn)
2022-02-27 21:35:32 6864
原创 Leetcode 刷题笔记 (double pointers)
Leetcode 刷题笔记 double pointers双指针167. Two Sum II - Input Array Is Sorted (medium)88. Merge Sorted Array (easy)142. Linked List Cycle II (medium)633. Sum of Square Numbers (medium)680. Valid Palindrome II (easy)双指针start, end 头尾两个指针相向移动进行数组的搜索通常用于有序数组的搜索或
2022-02-23 14:14:56 258
原创 Leetcode 刷题笔记 (sliding window)
Leetcode 刷题笔记滑动窗口209 (medium)76 (hard)1456 (medium)滑动窗口滑动窗口适合子数组的搜索同向双指针检索数组,通过start 和 end 指针定位滑动窗口思想:滑动 end 指针 将s[end] 加入窗口,满足要求后移出s[start] 并将start 指针前移 进行窗口的滑动。209 (medium)class Solution: def minSubArrayLen(self, target: int, nums: List[int])
2022-02-21 14:16:47 227
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人