题解 | #买卖股票的最好时机(一)#
买卖股票的最好时机(一)
http://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec
import java.util.*;
public class Solution {
public int maxProfit (int[] prices) {
int min = Integer.MAX_VALUE;
int maxProfit = 0;
for (int p : prices) {
maxProfit = Math.max(maxProfit, p - min);
min = Math.min(p, min);
}
return maxProfit;
}
}