diff --git a/LeetCode-CN/354.cpp b/LeetCode-CN/354.cpp new file mode 100644 index 0000000..b6184c1 --- /dev/null +++ b/LeetCode-CN/354.cpp @@ -0,0 +1,24 @@ +class Solution { +public: + int maxEnvelopes(vector>& envelopes) { + const int N = envelopes.size(); + + sort(envelopes.begin(), envelopes.end(), [](vector& a, vector& b) { + return a[0] < b[0]; + }); + + vector dp(N); + for (int i = 0; i < N; i++) { + dp[i] = 1; + } + for (int i = 1; i < N; i++) { + for (int j = 0; j < i; j++) { + if (envelopes[i][0] > envelopes[j][0] && envelopes[i][1] > envelopes[j][1]) { + dp[i] = max(dp[i], dp[j] + 1); + } + } + } + + return *max_element(dp.begin(), dp.end()); + } +}; \ No newline at end of file