455
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(),g.end());
sort(s.begin(),s.end());
int index = s.size() - 1;
int res = 0;
for(int i = g.size() - 1; i >= 0; i-- ){
if( index >= 0 && s[index] >= g[i]){
res++;
index--;
}
}
return res;
}
};
376
class Solution {
public:
int wiggleMaxLength(vector<int>& nums) {
int res = 1;
int reg = 0;
int reg_before = 0;
if(nums.size() <= 1) return nums.size();
for(int i = 0; i < nums.size() - 1; i++){
reg = nums[i+1] - nums[i];
if((reg_before >= 0 && reg < 0) || (reg_before <= 0 && reg > 0)){
res++;
reg_before = reg;
}
}
return res;
}
};
53
class Solution {
public:
int maxSubArray(vector<int>& nums) {
int result = INT32_MIN;
int count = 0;
for (int i = 0; i < nums.size(); i++) {
count += nums[i];
result = count > result ? count : result;
if (count < 0) count = 0;
}
return result;
}
};