5.22
public class Solution {
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
public int maxProfit(int[] prices) {
// write your code here
int max = 0;
int length = prices.length;
if(length <= 1){
return 0;
}
for(int i = 0;i < length -1;i++){
for(int j = i+1;j < length;j++){
int tmp = prices[j] - prices[i];
if(tmp > max){
max = tmp;
}
//System.out.println(i +"," + j + ",tmp:" + tmp);
}
}
return max;
}
}