File tree Expand file tree Collapse file tree
best-time-to-buy-and-sell-stock Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution :
2+ def maxProfit (self , prices : list [int ]) -> int :
3+ """
4+ ์ฃผ์ ๊ฐ๊ฒฉ ๋ชฉ๋ก์์ ์ต๋ ์ด์ต์ ๊ณ์ฐํ๋ ํจ์.
5+
6+ ์๊ฐ ๋ณต์ก๋: O(N)
7+ ๊ณต๊ฐ ๋ณต์ก๋: O(1)
8+
9+ Args:
10+ prices (list[int]): ์ฃผ์ ๊ฐ๊ฒฉ ๋ชฉ๋ก
11+
12+ Returns:
13+ int: ์ต๋ ์ด์ต
14+ """
15+ min_price = prices [0 ]
16+ max_profit = 0
17+ for price in prices [1 :]:
18+ max_profit = max (max_profit , price - min_price )
19+ min_price = min (min_price , price )
20+ return max_profit
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def groupAnagrams (self , strs : list [str ]) -> list [list [str ]]:
3+ """
4+ ๋จ์ด ๋ชฉ๋ก์์ ์ ๋๊ทธ๋จ๋ผ๋ฆฌ ๊ทธ๋ฃนํํด์, ๊ทธ๋ฃนํ๋ ๋จ์ด ๋ชฉ๋ก์ ๋ฐํํ๋ ํจ์.
5+
6+ N์ ๋จ์ด์ ๊ฐ์, M์ ๋จ์ด์ ์ต๋ ๊ธธ์ด๋ก ๊ฐ์ ํ ๋,
7+ ์๊ฐ ๋ณต์ก๋: O(N * M log M)
8+ ๊ณต๊ฐ ๋ณต์ก๋: O(N * M)
9+
10+ Args:
11+ strs (list[str]): ๋จ์ด ๋ชฉ๋ก
12+
13+ Returns:
14+ list[list[str]]: ์ ๋๊ทธ๋จ ๊ทธ๋ฃนํ๋ ๋จ์ด ๋ชฉ๋ก
15+ """
16+ seen = dict ()
17+ for st in strs :
18+ st_key = "" .join (sorted (st ))
19+ if st_key in seen :
20+ seen [st_key ].append (st )
21+ else :
22+ seen [st_key ] = [st ]
23+ return list (seen .values ())
You canโt perform that action at this time.
0 commit comments