Skip to content

Instantly share code, notes, and snippets.

@svaza
Created August 7, 2022 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svaza/32a8dc4eded5655ea1bdf584c3ed22e2 to your computer and use it in GitHub Desktop.
Save svaza/32a8dc4eded5655ea1bdf584c3ed22e2 to your computer and use it in GitHub Desktop.
aritmmetic triplets
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