Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int GetLongestSubArray(int[] array)
- {
- var firstPosition = 0;
- var length = 1;
- var currentFirstPosition = 0;
- var currentLength = 1;
- for (var i = 1; i < array.Length; i++)
- {
- if (array[i] == currentFirstPosition)
- {
- currentLength++;
- }
- else
- {
- currentLength = 1;
- currentFirstPosition = i;
- }
- if (currentLength > length)
- {
- length = currentLength;
- firstPosition = currentFirstPosition;
- }
- }
- return firstPosition;
- }
Advertisement
Add Comment
Please, Sign In to add comment