Created
May 24, 2015 21:40
-
-
Save rootid/348ff506c848c8b18ca3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Find Idx difference | |
//Input: {34, 8, 10, 3, 2, 80, 30, 33, 1} | |
//Output: 78 | |
//Input: {9, 2, 3, 4, 5, 6, 7, 8, 18, 0} | |
//Output:16 | |
//Input: {1, 2, 3, 4, 5, 6} | |
//Output: 5 | |
//Input: {6, 5, 4, 3, 2, 1} | |
//Output: 0 | |
public static int getMaxDifference (int a[]) { | |
int len = a.length; | |
int result = 0; | |
if (len > 1) { | |
int min = a[0]; | |
for (int i=1;i<len;i++) { | |
if (min > a[i]) { | |
min = a[i]; | |
} else { | |
if (result < (a[i] - min) ) { | |
result = a[i] - min; | |
} | |
} | |
} | |
} | |
//System.out.println(result); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment