오늘의 문제 _ 121. Best Time to Buy and Sell Stock(LeetCode)
나의 풀이
class Solution {
public int maxProfit(int[] prices) {
int buy = Integer.MAX_VALUE;
int sell = -1;
for (int price : prices) {
buy = Math.min(price, buy);
sell = Math.max(sell, price - buy);
}
return sell;
}
}
'TIL' 카테고리의 다른 글
TIL _ 동적계획법 _ 0831 _ SAT (0) | 2024.08.31 |
---|---|
TIL _ 동적계획법 _ 0830 _ FRI (0) | 2024.08.31 |
TIL _ 탐욕법(Greedy) _ 0829 _ THU (0) | 2024.08.30 |
TIL _ 탐욕법(Greedy) _ 0828 _ WED (0) | 2024.08.29 |
TIL _ 완전탐색 _ 0827 _ TUE (0) | 2024.08.28 |