Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- var m1 = new int[]{ 1, 2, 3, 2, 3, 5, 5, 3, 7, 1, 2, 4, 8, 9, 11, 12, 1, 1, 1 };
- var m2 = new int[] { 1, 2, 3 };
- Console.Write(MaxLength(m2));
- Console.Read();
- }
- public static int MaxLength(int[] arr)
- {
- if (arr == null) return 0;
- if (arr.Length < 2) return arr.Length;
- var max = 0;
- var i = 0;
- var j = 1;
- var curLen = 1;
- while (j < arr.Length)
- {
- if (arr[i] <= arr[j])
- {
- curLen++;
- i++;
- }
- else
- {
- if (curLen > max) max = curLen;
- i = j;
- curLen = 1;
- }
- j++;
- }
- return Math.Max(max, curLen);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement