leetcode

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

2091.cpp (598B)


      1 class Solution {
      2   public:
      3     int minimumDeletions(const vector<int> &nums) const {
      4         const int n = size(nums);
      5         int mini = nums[0], imini = 0;
      6         int maxi = nums[0], imaxi = 0;
      7 
      8         for (int i = 1; i < n; i++) {
      9             if (mini > nums[i]) {
     10                 mini = nums[i];
     11                 imini = i;
     12             }
     13 
     14             if (maxi < nums[i]) {
     15                 maxi = nums[i];
     16                 imaxi = i;
     17             }
     18         }
     19 
     20         return min(
     21             {imini + n - imaxi + 1, imaxi + n - imini + 1, max(imini, imaxi) + 1, n - min(imini, imaxi)});
     22     }
     23 };