File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
best-time-to-buy-and-sell-stock Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ์๊ฐ๋ณต์ก๋: O(n)
2
+ // ๊ณต๊ฐ๋ณต์ก๋: O(1)
3
+
4
+ // ์ต์๊ฐ์ ๊ณ์ ๊ฐฑ์ ํ๋ฉด์ ์ต๋ ์ด์ต์ ๊ณ์ฐ
5
+
6
+ /**
7
+ * @param {number[] } prices
8
+ * @return {number }
9
+ */
10
+ var maxProfit = function ( prices ) {
11
+ let minPrice = Infinity ;
12
+ let maxProfit = 0 ;
13
+
14
+ for ( let price of prices ) {
15
+ if ( price < minPrice ) {
16
+ minPrice = price ;
17
+ } else {
18
+ maxProfit = Math . max ( maxProfit , price - minPrice ) ;
19
+ }
20
+ }
21
+
22
+ return maxProfit ;
23
+ } ;
24
+
Original file line number Diff line number Diff line change
1
+ // ์๊ฐ๋ณต์ก๋: O(n * m log m)
2
+ // ๊ณต๊ฐ๋ณต์ก๋: O(n)
3
+
4
+ // HashMap ์ฌ์ฉ
5
+ // ๊ฐ ๋ฌธ์์ด์ ์ ๋ ฌํ์ฌ ํค๋ก ์ฌ์ฉ
6
+ // ์ ๋ ฌ๋ ๋ฌธ์์ด์ ํค๋ก ์ฌ์ฉํ์ฌ ๊ทธ๋ฃนํ
7
+
8
+ /**
9
+ * @param {string[] } strs
10
+ * @return {string[][] }
11
+ */
12
+ var groupAnagrams = function ( strs ) {
13
+ const map = { } ;
14
+
15
+ for ( const str of strs ) {
16
+ const key = str . split ( '' ) . sort ( ) . join ( '' ) ;
17
+ if ( ! map [ key ] ) {
18
+ map [ key ] = [ ] ;
19
+ }
20
+ map [ key ] . push ( str ) ;
21
+ }
22
+
23
+ return Object . values ( map ) ;
24
+ } ;
25
+
You canโt perform that action at this time.
0 commit comments