Wacky_rubia

Untitled

Oct 3rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. public int GetLongestSubArray(int[] array)
  2. {
  3.     var firstPosition = 0;
  4.     var length = 1;
  5.  
  6.  
  7.     var currentFirstPosition = 0;
  8.     var currentLength = 1;
  9.  
  10.     for (var i = 1; i < array.Length; i++)
  11.     {
  12.         if (array[i] == currentFirstPosition)
  13.         {
  14.             currentLength++;
  15.         }
  16.         else
  17.         {
  18.             currentLength = 1;
  19.             currentFirstPosition = i;
  20.         }
  21.         if (currentLength > length)
  22.         {
  23.             length = currentLength;
  24.             firstPosition = currentFirstPosition;
  25.         }
  26.     }
  27.  
  28.     return firstPosition;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment