Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int maxDifference(int[] a)
- {
- int high = a[0];
- int low = a[0];
- int diff = -1;
- for (int i = 1; i < a.Length; i++)
- {
- int current = a[i];
- if (current > high)
- {
- high = current;
- diff = high - low;
- continue;
- }
- if (current < low)
- {
- low = current;
- high = diff > 0 ? low + diff : low;
- }
- }
- return diff;
- }
Advertisement
Add Comment
Please, Sign In to add comment