Skip to content

Latest commit

 

History

History

number-of-arithmetic-triplets

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Number of arithmetic triplets

Problem link

Solutions

Solution.cpp

// https://leetcode.com/problems/number-of-arithmetic-triplets

class Solution {
 public:
  int arithmeticTriplets(vector<int>& nums, int diff) {
    int n = nums.size(), ret{};
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < i; ++j)
        for (int k = 0; k < j; ++k)
          if (nums[i] - nums[j] == diff and nums[j] - nums[k] == diff) ++ret;
    return ret;
  }
};

Tags