leetcode :Binary Search:Russian Doll Envelopes(354)
来源:互联网 发布:淘宝红包怎样设 编辑:程序博客网 时间:2024/05/16 01:53
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(); }};
0 0
- leetcode :Binary Search:Russian Doll Envelopes(354)
- 【Leetcode】Russian Doll Envelopes
- leetcode Russian Doll Envelopes
- LeetCode Russian Doll Envelopes
- LeetCode -- Russian Doll Envelopes
- 【Leetcode】Russian Doll Envelopes
- [LeetCode] Russian Doll Envelopes
- [leetcode-354]Russian Doll Envelopes(java)
- [leetcode-354]Russian Doll Envelopes(java)
- LeetCode No.354 Russian Doll Envelopes
- LeetCode 354. Russian Doll Envelopes
- leetcode 354. Russian Doll Envelopes
- [leetcode] 354. Russian Doll Envelopes
- leetcode之Russian Doll Envelopes
- leetcode.354. Russian Doll Envelopes
- leetcode 354. Russian Doll Envelopes
- leetcode 354.Russian Doll Envelopes
- LeetCode 354. Russian Doll Envelopes
- laravel中带有条件搜索的分页
- cocos2dx c++实现小游戏--华容道
- [基环] codeforces 711D. Directed Roads
- 区域卫生数据存储方式
- intent传值收不到 onNewIntent
- leetcode :Binary Search:Russian Doll Envelopes(354)
- 【Android】DataBinding库(MVVM设计模式)
- 中文拼音分词
- javascript打印菱形和镂空菱形
- jQuery(function(){})与(function(){})(jQuery)的区别
- tomcat启动错误
- *浙大PAT甲级 1089 归并排序与插入排序
- Windows明文密码抓取 法国神器mimikatz_trunk附源码
- 根据帧图自动生成android 动画xml文件--python脚本