You are viewing a single comment's thread. Return to all comments →
c# version
public static int pickingNumbers(List<int> a) { var d = new Dictionary<int, int>(); // [n,q] foreach(int n in a) { int q; if (d.TryGetValue(n, out q)) { d[n] = q + 1; } else { d[n] = 1; } } int mx = 0; foreach(var x in d) { int xk = x.Key; int xv = x.Value; int q = 0; foreach(var y in d) { int yk = y.Key; if ( xk != yk && Math.Abs(xk - yk) < 2 ) { q = xv + y.Value; } } if (xv > q) { q = xv; } if (q > mx) { mx = q; } } return mx; }
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# version