Created
May 2, 2015 16:48
-
-
Save stephen-maina/75f6a301d79c6a647607 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
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
if(A.length==0){ | |
return 0; | |
} | |
int ans=0; | |
int min=Integer.MAX_VALUE; | |
for(int index=0;index<A.length;index++){ | |
if(A[index]<min){ | |
min=A[index]; | |
}else{ | |
ans= Math.max(ans,A[index]-min); | |
} | |
} | |
return ans; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment