File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
best-time-to-buy-and-sell-stock Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change 33- [ ๋ต์ ์ฝ๋ ์ ์ถ๋ฒ] ( https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C )
44
55# Problem
6- - ๋ฌธ์ ๋งํฌ :
7- - ๋ฌธ์ ์ด๋ฆ :
8- - ๋ฌธ์ ๋ฒํธ :
9- - ๋์ด๋ :
6+ - ๋ฌธ์ ๋งํฌ : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
7+ - ๋ฌธ์ ์ด๋ฆ : Best Time to Buy and Sell Stock
8+ - ๋ฌธ์ ๋ฒํธ : 121
9+ - ๋์ด๋ : easy
1010- ์นดํ
๊ณ ๋ฆฌ :
1111
1212# ๋ฌธ์ ์ค๋ช
1919
2020# โ
์ฝ๋ (Solution)
2121
22+ ``` cpp
23+ class Solution {
24+ public:
25+ int maxProfit(vector<int >& prices) {
26+ int localMax = prices[ prices.size()-1] ;
27+ int res = 0;
28+ for(int i=prices.size()-2;i>=0;i--){
29+ localMax = max(localMax, prices[ i] );
30+ res = max(res, localMax-prices[ i] );
31+ }
32+
33+ return res;
34+ }
35+ };
36+ ```
37+
2238# ๐ ์ฝ๋ ์ค๋ช
2339
40+ - local max๋ฅผ ์ค์
2441
2542# ์ต์ ํ ํฌ์ธํธ (Optimality Discussion)
2643โข ์ต์ ํํ ์ด์ ์ ์๋ฆฌ
You canโt perform that action at this time.
0 commit comments