今日学习的文章链接和视频链接
- https://programmercarl.com/0977.有序数组的平方.html
- https://programmercarl.com/0209.长度最小的子数组.html
- https://programmercarl.com/0059.螺旋矩阵II.html
977.有序数组的平方
菜鸡刚开始只会暴力,记录一下双指针:
var sortedSquares = function(nums) {
let result = []
let k = nums.length-1
let j = nums.length-1;
let i = 0;
while(i<=j){
if(nums[i]*nums[i]>nums[j]*nums[j]){
result[k--] = nums[i]*nums[i]
i++
}else{
result[k--] = nums[j]*nums[j]
j--
}
}
return result
};
209.长度最小的子数组
滑动窗口的机制:
var minSubArrayLen = function(target, nums) {
let result = nums.length+1;
let i = 0 ;
let j = 0 ;
let sum = 0
for( ; j<nums.length ; j++){
sum += nums[j];
while(sum>=target){
result = result < j-i+1 ? result : j-i+1;
// console.log(re)
sum -= nums[i++]
// console.log(sum)
}
}
if(nums.length+1 === result){
result = 0
}
return result
};
59.螺旋矩阵II
一定要记住在三个边遍历的过程中一定要区间确定。
var minSubArrayLen = function(target, nums) {
let result = nums.length+1;
let i = 0 ;
let j = 0 ;
let sum = 0
for( ; j<nums.length ; j++){
sum += nums[j];
while(sum>=target){
result = result < j-i+1 ? result : j-i+1;
// console.log(re)
sum -= nums[i++]
// console.log(sum)
}
}
if(nums.length+1 === result){
result = 0
}
return result
};
今日收获,记录一下自己的学习时长
标签:977,nums,sum,随想录,length,let,result,数组 From: https://www.cnblogs.com/lijiacheng/p/17791729.html3h