leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0962.cpp (520B)


      1 class Solution {
      2   public:
      3     int maxWidthRamp(const vector<int> &nums) const {
      4         vector<pair<int, int>> vec;
      5         int res = 0;
      6 
      7         for (int i = 0; i < size(nums); i++) {
      8             if (empty(vec) || vec.back().first > nums[i])
      9                 vec.emplace_back(nums[i], i);
     10             else {
     11                 const auto opt = lower_bound(begin(vec), end(vec), make_pair(nums[i], INT_MAX), greater());
     12                 res = max(res, i - opt->second);
     13             }
     14         }
     15 
     16         return res;
     17     }
     18 };