重练算法(代码随想录版)day1-2 - 数组
最近秋招发现算法写起来手生了,之前的刷题量也一般,为了秋招和以后工作,打算重新捡起来练习。
这次为了提高自己的专注度,打算跟着代码随想录的顺序去刷题,大概用两个月的时间把经典题型重过一轮。
两日刷题量:18
当前刷题总量:18
Easy: 11
Mid: 6
Hard: 1
Day 1-2 数组
基础理论:
- 数组是相同类型元素的集合,存储在连续的内存空间
- 通过索引访问对应元素,下标从0开始
- 删除或添加元素需要移动后续元素位置
常用思想及练习题目:
- 二分查找(注意明确区间定义)
- 704.二分查找(easy):https://leetcode.cn/problems/binary-search/description/
- 35.搜索插入位置(easy):https://leetcode.cn/problems/search-insert-position/description/
- 34.在排序数组中查找元素的第一个和最后一个位置(mid):https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/description/
- 69.x的平方根(easy):https://leetcode.cn/problems/sqrtx/description/
- 367.有效的完全平方数(easy):https://leetcode.cn/problems/valid-perfect-square/description/
- 双指针法
- 27.移除元素(easy):https://leetcode.cn/problems/remove-element/description/
- 26.删除排序数组中的重复项(easy):https://leetcode.cn/problems/remove-duplicates-from-sorted-array/description/
- 283.移动零(easy):https://leetcode.cn/problems/move-zeroes/description/
- 844.比较含退格的字符串(easy):https://leetcode.cn/problems/backspace-string-compare/description/
- 977.有序数组的平方(easy):https://leetcode.cn/problems/squares-of-a-sorted-array/description/
- 滑动窗口 (left、right双指针维护窗口,right负责扩展窗口,left负责收缩窗口, 注意检查条件和更新结果)
- 209.长度最小子数组(mid):https://leetcode.cn/problems/minimum-size-subarray-sum/description/
- 904.水果成篮(mid):https://leetcode.cn/problems/fruit-into-baskets/description/
- 76.最小覆盖子串(hard):https://leetcode.cn/problems/minimum-window-substring/
- 螺旋矩阵 (注意边界条件的判断)
- 59.螺旋矩阵Ⅱ(mid) :https://leetcode.cn/problems/spiral-matrix-ii/description/
- 54.螺旋矩阵(mid):https://leetcode.cn/problems/spiral-matrix/description/
- LCR 146.螺旋遍历二维数组(easy):https://leetcode.cn/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/description/
- 前缀和 (一维、二维前缀和)
- 58.区间和(easy) :https://kamacoder.com/problempage.php?pid=1070
- 44.开发商购买土地(mid):https://kamacoder.com/problempage.php?pid=1044
补充二维前缀和相关:
- 二维前缀和数组定义:sum[i][j] = 从 (0,0) 到 (i,j) 这个矩形的所有元素之和
- 递推公式sum[i][j]= matrix[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
- 如求任意子矩形 (x1, y1) → (x2, y2) 的和:rect_sum = sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1]。

浙公网安备 33010602011771号