Advertisement
Guest User

PickingNums

a guest
Jan 28th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  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.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement