算法练习Day2 | 数组

82 阅读1分钟

977.有序数组的平方

问题

Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.

LC链接
leetcode.com/problems/sq…

文章讲解
programmercarl.com/0977.%E6%9C…

注意点
Two pointers, 因为平方后的值是向内递减.

209.长度最小的子数组

问题

Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead.

LC链接
leetcode.com/problems/mi…

文章讲解
programmercarl.com/0209.%E9%95…

注意点
Sliding window, 同two pointers类似.
两层循环可以看成滑动窗口的冗余版, 每次窗口前沿移动时, 后沿都需要从前沿开始遍历, 删掉这部分冗余即可.

59.螺旋矩阵II

模拟题, 需关注边界范围(开和闭), 以及保持模拟循环不变量.

文章讲解
programmercarl.com/0059.%E8%9E…