leetcode

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

1502.cpp (359B)


      1 class Solution {
      2   public:
      3     bool canMakeArithmeticProgression(vector<int> &arr) {
      4         int n = arr.size();
      5         if (n <= 2) return true;
      6         sort(arr.begin(), arr.end());
      7         int delta = arr[1] - arr[0];
      8         for (int i = 2; i < n; i++) {
      9             if (arr[i] - arr[i - 1] != delta) return false;
     10         }
     11         return true;
     12     }
     13 };