SHARE
TWEET

PickingNums

a guest Jan 28th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    public static int PickingNumbers(List<int> a)
  2.     {
  3.         int length = 0;
  4.         int temp = 0;
  5.         int firstNumberOfSeq = -1;
  6.         a.Sort();
  7.  
  8.         for (int i = 1; i < a.Count; ++i)
  9.         {
  10.             int difference = a[i] - a[i - 1];
  11.  
  12.             if (firstNumberOfSeq == -1 && difference <= 1 && difference >= 0)
  13.             {
  14.                 firstNumberOfSeq = a[i - 1];
  15.             }
  16.  
  17.             if (a[i] - firstNumberOfSeq < 2)
  18.             {
  19.                 temp++;
  20.             }
  21.             else
  22.             {
  23.                 temp = 0;
  24.                 firstNumberOfSeq = -1;
  25.             }
  26.  
  27.             if (temp > length)
  28.             {
  29.                 length = temp;
  30.             }
  31.         }
  32.  
  33.         return length;
  34.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top