sort(children.begin(), children.end());
sort(v.begin(), v.end(), [](int a, int b) { return abs(a)<abs(b); });
// 在一个算法中,下面这个没有使用引用,结果一直超时
sort(intervals.begin(), intervals.end(), [](vector<int> a, vector<int> b) {
return a[1] < b[1];
});
// 正确写法应该使用引用传递参数,使用引用传省了复制vector所有成员这一步,在这只用复制一个引用(指针)直接就可以了
auto compare = [](vector<int>& a, vector<int>& b) {return a[0] < b[0];};
sort(intervals.begin(), intervals.end(), compare);
max(num[i-1], num[i] + 1);
accumulate(num.begin(), num.end(), 0);
LeetCode常用 CPP算法
于 2022-04-25 11:32:19 首次发布