Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created May 2, 2015 16:48
Show Gist options
  • Save stephen-maina/75f6a301d79c6a647607 to your computer and use it in GitHub Desktop.
Save stephen-maina/75f6a301d79c6a647607 to your computer and use it in GitHub Desktop.
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