class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(s.begin(), s.end());
sort(g.begin(), g.end());
int intIndex = 0;
for(int i = 0; i < s.size(); i++){
if(intIndex < g.size() && s[i] >= g[intIndex]){
intIndex++;
}
}
return intIndex;
}
};
class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int result = 1;
int curDiff = 0;
int preDiff = 0;
for(int i = 0; i < nums.size()-1; i++){
curDiff = nums[i+1] - nums[i];
if((preDiff <= 0 && curDiff > 0) || (preDiff >= 0 && curDiff < 0)){
result++;
preDiff = curDiff;
}
}
return result;
}
};
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int count = 0;
int result = INT_MIN;
for(int i = 0; i < nums.size(); i++){
count += nums[i];
if(count > result) result = count;
if(count < 0) count = 0;
}
return result;
}
};