You are viewing a single comment's thread. Return to all comments →
C#
public static int pairs(int k, List<int> arr) { var hashSet = new HashSet<int>(arr); return hashSet.Count(x => hashSet.Contains(x + k)); } public static int pairs(int k, List<int> arr) { var total = 0; var hashSet = new HashSet<int>(arr); foreach (var n in hashSet) { if (hashSet.Contains(n + k)) { total++; } } return total; }
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
C#