leetcode

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

1464.cpp (413B)


      1 class Solution {
      2   public:
      3     int maxProduct(const vector<int> &nums) const {
      4         int a = max(nums[0], nums[1]);
      5         int b = min(nums[0], nums[1]);
      6         for (int i = 2; i < nums.size(); i++) {
      7             if (nums[i] > a) {
      8                 b = a;
      9                 a = nums[i];
     10             } else {
     11                 b = max(b, nums[i]);
     12             }
     13         }
     14         return (a - 1) * (b - 1);
     15     }
     16 };