354 题测试数据加强了
Anudorannador opened this issue · comments
Anudorannador commented
354 题,Russian Doll Envelopes 的数据貌加强了,$1 \leqslant \text{envelopes.length} \leqslant 10^5$ ,$O(N^2)$ 的算法过不了了,我直接把老师你的代码(v1版本)复制粘贴上去直接 TLE 了。(我自己之前提交了AC过的
YaoyaoChang commented
您好,您的邮件我已经收到,我一定会尽快回复的!谢谢!【此为自动回复邮件】Hello, I've received your email. I will reply to you as soon as possible! Thank you! 【This is an automatic reply email】
yangizone commented
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
Aryaveer Singh commented
This should work:
`
class Solution {
public:
static bool comp(vector& A, vector& B){
if(A[0] == B[0]){
return A[1] > B[1];
}
return A[0] < B[0];
}
static bool comp1(const vector<int>& A, const vector<int>& B){
return A[1] < B[1];
}
int maxEnvelopes(vector<vector<int>>& nums) {
int n = nums.size();
sort(begin(nums), end(nums), comp);
vector<vector<int>> ans;
ans.push_back(nums[0]);
for(int i = 1; i < n; i++){
if(nums[i][0] > ans.back()[0] and nums[i][1] > ans.back()[1]){
ans.push_back(nums[i]);
}else{
int idx = lower_bound(begin(ans), end(ans), nums[i], comp1) - ans.begin();
ans[idx] = nums[i];
}
}
for(auto x: ans){
cout << x[0] << " " << x[1] << "\n";
}
return ans.size();
}
};
`
wisdompeak commented
这个库里贴的代码不一定都是AC的,只是用来说明时间复杂度的影响。