You are viewing a single comment's thread. Return to all comments →
C#: O(nlogn) public static int pickingNumbers(List a) { if (a.Count <= 1) return a.Count;
a.Sort(); int result = 0; int currentCount = 1; for (int i = 0, j = 1; j < a.Count; j++) { if (a[j] - a[i] <= 1) { currentCount++; } else { result = Math.Max(result, currentCount); currentCount = 1; i = j; } } result = Math.Max(result, currentCount); return result; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
C#: O(nlogn)
public static int pickingNumbers(List a) { if (a.Count <= 1) return a.Count;
}