977.有序数组的平方
fail
其实想到双指针了,但是又想空间复杂度为O(1),发现实现不了,浪费了有效时间
209.长度最小的子数组
Accept
经典for while组合,滑动窗口问题
public class test {
public static void main(String[] args) {
int a[] = {2,3,1,2,4,3};
int target = 7;
int j = 0;
int sum = 0, minLength = a.length;
for (int i = 0; i < a.length; i++) {
sum += a[i];
while (sum > target){
sum -= a[j++];
}
if (sum == target){
minLength = Math.min(minLength, i - j +1);
}
}
System.out.println(minLength);
}
}
1098

被折叠的 条评论
为什么被折叠?



