买卖股票的最佳时机

public class Solution {
/**
* @param prices: Given an integer array
* @return: Maximum profit
*/
public int maxProfit(int[] prices) {
// write your code here
int Max = 0;
if( prices == null || prices.length == 0)
return 0;

for(int i = 0;i< prices.length ;i++){
for(int j = i;j< prices.length ;j++)
Max = Math.max(Max, prices[j] - prices[i]);
}
return Max;
}
}

posted @ 2017-03-08 22:56  逸文皓  阅读(81)  评论(0编辑  收藏  举报