努力刷题 day2

1.LeetCode 977. 有序数组的平方 传送门

code

1
2
3
4
5
6
7
8
9
10
class Solution {
public int[] sortedSquares(int[] nums) {
for(int i=0;i<nums.length;i++)
{
nums[i]=nums[i]*nums[i];
}
Arrays.sort(nums);
return nums;
}
}

2.LeetCode 209. 长度最小的子数组传送门

code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public int minSubArrayLen(int s, int[] nums) {
int n = nums.length;
if (n == 0) {
return 0;
}
int ans = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = i; j < n; j++) {
sum += nums[j];
if (sum >= s) {
ans = Math.min(ans, j - i + 1);
break;
}
}
}
return ans == Integer.MAX_VALUE ? 0 : ans;
}
}
今日份总结

(1) Arrays.sort () 使用方法:传送门 - 转载 - 侵删致谢
(2)Integer.MAX_VALUE 的含义:传送门 - 转载 - 侵删致谢

更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

周周 微信支付

微信支付

周周 支付宝

支付宝