class Solution {
public:
int findContentChildren(vector& g, vector& s) {
//每次选最小的饼干看是否能满足某个孩子
sort(s.begin(),s.end());
sort(g.begin(),g.end());
int cnt=0;
int indexS=0;
int indexG=0;
for(int i=indexS;i=g[j])
{
++cnt;
++indexG;
++indexS;
break;
}
}
}
return cnt;
}
};
减少循环
class Solution {
public:
int findContentChildren(vector& g, vector& s) {
sort(s.begin(),s.end());
sort(g.begin(),g.end());
int indexS=0;
int res=0;
for(int i=0;i
376 摆动序列
class Solution {
public:
int wiggleMaxLength(vector& nums) {
if(nums.size()==1) return nums.size();
int cnt=1;
int DiffPre=0;
int DiffCur;
for(int i=0;i0&&DiffPre<=0)
||(DiffCur<0&&DiffPre>=0)
)
{
DiffPre=DiffCur;
++cnt;
}
}
return cnt;
}
};
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)