- leetcode:121. Best Time to Buy a
- LeetCode #121 #122 #123 #188 #30
- #121. Best Time to Buy and Sell
- [LeetCode] 121. Best Time to Buy
- Leetcode121 - 123 (dp problems)
- [数组]121. Best Time to Buy and Se
- 121. Best Time to Buy and Sell S
- Leetcode121-Best Time to Buy and
- 每天(?)一道LeetCode(14) Best Time to
- Leetcode 股票合集 【121、122、714、309】
maintain the "max_profit" and "min_price".
public class Solution {
public int max_profit(int[] prices) {
int min_price = Integer.MAX_VALUE;
int max_pro = 0;
for (int i=0; i<prices.length; i++) {
min_price = Math.min(min_price, prices[i]);
max_pro = Math.max(max_pro, prices[i]-min_price);
}
return max_pro;
}
}
网友评论