Clean C++ 11 Implementation with Explaination refered from @kamyu104
It is easy to relate this problem with the previous LIS problem. But how to solve it under the 2 dimensional cases. The key ideas lay at that how we deal with t
It is easy to relate this problem with the previous LIS problem. But how to solve it under the 2 dimensional cases. The key ideas lay at that how we deal with the equal width but different hight cases.  \n\nA clever solution is to sort the pair<int,int> array according the width, if the width is equal, just sort by the height reversely.  \n\nThen we can get the following solutions :  \n\n    class Solution {\n    public:\n        int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n            int size_ = envelopes.size();\n            if(size_ < 2)  return size_; \n            sort(envelopes.begin(), envelopes.end(), \n                [](const pair<int, int>& a, const pair<int, int>& b) {\n                    if(a.first == b.first) {\n                        return a.second > b.second;\n                    }\n                    else {\n                        return a.first < b.first;\n                    }\n                });\n            /** find the LIS of the height, as we have filtered the width equal cases **/\n            vector<int> result;\n            for (const auto& iter : envelopes) {\n                const auto target = iter.second;\n                auto cur = lower_bound(result.begin(), result.end(), target);\n                if (cur == result.end()) {\n                    result.emplace_back(target);\n                } else {\n                    *cur = target;\n                }\n            }\n            return result.size();\n        }\n    };
[]