class Solution {
public int wiggleMaxLength(int[] nums) {
if (nums.length <= 1) return nums.length;
int pre = 0;
int cur = 0;
int res = 1;
for (int i = 0; i < nums.length - 1; i++) {
cur = nums[i + 1] - nums[i];
if (pre <= 0 && cur > 0 || pre >= 0 && cur < 0) {
res++;
pre = cur;
}
}
return res;
}
}
class Solution {
public int maxSubArray(int[] nums) {
int max = Integer.MIN_VALUE;
int sum = 0;
for (int i = 0; i < nums.length; i++) {
sum += nums[i];
max = Math.max(max, sum);
if (sum <= 0) sum = 0;
}
return max;
}
}