455. 分发饼干
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int biscuit = 0, hunger = 0;
for (biscuit = 0; biscuit < s.length && hunger < g.length; biscuit++) {
if (s[biscuit] >= g[hunger]) {
hunger++;
}
}
return hunger;
}
376. 摆动序列
public int wiggleMaxLength(int[] nums) {
if (nums.length <= 1) {
return nums.length;
}
int result = 1;
int pre = 0, cur;
for (int i = 1; i < nums.length; i++) {
cur = nums[i] - nums[i - 1];
if ((pre <= 0 && cur > 0) || (pre >= 0 && cur < 0)) {
result++;
}
if (cur != 0) {
pre = cur;
}
}
return result;
}
53. 最大子数组和
public int maxSubArray(int[] nums) {
int result = Integer.MIN_VALUE;
int count = 0;
for (int num : nums) {
count += num;
result = Math.max(result, count);
if (count < 0) {
count = 0;
}
}
return result;
}
标签:count,兆头,hunger,int,biscuit,nums,瞬间,result,心想
From: https://www.cnblogs.com/Chain-Tian/p/17048392.html