landscapemi的博客

###### leetcode :Binary Search：Russian Doll Envelopes(354)

You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is greater than the width and height of the other envelope.

What is the maximum number of envelopes can you Russian doll? (put one inside other)

Example:
Given envelopes = [[5,4],[6,4],[6,7],[2,3]], the maximum number of envelopes you can Russian doll is 3 ([2,3] => [5,4] => [6,7]).

http://www.cnblogs.com/grandyang/p/5568818.html

class Solution {
public:
int maxEnvelopes(vector<pair<int, int>>& envelopes) {
vector<int> dp;
sort(envelopes.begin(), envelopes.end(), [](const pair<int, int> &a, const pair<int, int> &b){
if (a.first == b.first) return a.second > b.second;
return a.first < b.first;
});
for (int i = 0; i < envelopes.size(); ++i) {
int left = 0, right = dp.size(), t= envelopes[i].second;
while (left < right) {
int mid = left + (right - left) / 2;
if (dp[mid] < t) left = mid + 1;
else right = mid;
}
if (right >= dp.size()) dp.push_back(t);
else dp[right] = t;
}
return dp.size();
}
};

#### [leetcode] 354. Russian Doll Envelopes 解题报告

2016-06-09 02:43:51

#### leetcode（354）—— Russian Doll Envelopes（俄罗斯套娃信封）

2016-06-13 23:05:32

#### leetcode 354. Russian Doll Envelopes

2016-06-10 18:52:29

#### LeetCode 354. Russian Doll Envelopes（信封包装）

2016-06-16 06:39:42

#### 【Leetcode】Russian Doll Envelopes

2016-06-07 15:51:54

#### Leetcode 354 Russian Doll Envelopes

2017-03-29 04:41:16

#### leetcode - 354 Russian Doll Envelopes

2017-11-16 17:09:00

#### leetcode 354 Russian Doll Envelopes 二元组最长递增子序列

2016-08-11 20:03:33

#### LeetCode -- Russian Doll Envelopes

2017-02-19 22:25:50

#### leetcode之Russian Doll Envelopes

2016-06-20 16:12:57

## 不良信息举报

leetcode :Binary Search：Russian Doll Envelopes(354)