Russian Doll Envelopes C++ solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n  static bool comp(vector<int> &a, vector<int> &b){\n      if(a[0] == b[0])\n        return a[1]>b[1];\n\n    return a[0]<b[0];\n  }\n  int solveOptimal(int n, vector<vector<int>>& envelopes){\n      if(n==0)\n       return 0;\n    vector<int> ans;\n    ans.push_back(envelopes[0][1]);\n    for(int i=1; i<n; i++){\n        if(envelopes[i][1]>ans.back())\n           ans.push_back(envelopes[i][1]);\n        else{\n            int index = lower_bound(ans.begin(),ans.end(),envelopes[i][1]) - ans.begin();\n            ans[index] = envelopes[i][1];\n        }\n    }\n    return ans.size();\n  }\n    int maxEnvelopes(vector<vector<int>>& envelopes) {\n        int n = envelopes.size();\n        sort(envelopes.begin(),envelopes.end(), comp);\n\n        return solveOptimal(n,envelopes);\n    }\n};\n```
['C++']