题解 | #买卖股票的最好时机#
买卖股票的最好时机
http://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
import java.util.*;
public class Solution {
/**
*
* @param prices int整型一维数组
* @return int整型
*/
public int maxProfit (int[] prices) {
if(prices.length == 0 || prices == null)
return 0;
int min = prices[0];
int max =0;
// write code here
for(int i=0;i< prices.length;i++){
min = Math.min(min,prices[i]);
max = Math.max(max,prices[i] - min);
}
return max;
}
} 
SHEIN希音公司福利 222人发布