Created
August 7, 2022 19:09
-
-
Save svaza/32a8dc4eded5655ea1bdf584c3ed22e2 to your computer and use it in GitHub Desktop.
aritmmetic triplets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int ArithmeticTriplets(int[] nums, int diff) { | |
var set = new HashSet<string>(); | |
int i = 0; | |
int n = nums.Length-1; | |
int c = 0; | |
while(i <= n-2) | |
{ | |
int j = i + 1; | |
while(j <= n) | |
{ | |
if(nums[j]-nums[i] == diff) | |
{ | |
int k = j + 1; | |
while(k <= n) | |
{ | |
if(nums[k]-nums[j] == diff) | |
{ | |
if(set.Add($"{nums[i]}-{nums[j]}-{nums[k]}")) | |
{ | |
c++; | |
} | |
break; | |
} | |
k++; | |
} | |
break; | |
} | |
j++; | |
} | |
i++; | |
} | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment