File tree Expand file tree Collapse file tree
find-minimum-in-rotated-sorted-array Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ ์ด๋ถํ์์ผ๋ก ์ ๋ ฌ ํ์. ์ต์๊ฐ์ด ๋ค์ด์๋ ๋ฒ์๋ฅผ ๋ฐํ์ผ๋ก ๊ณ์ ์ขํ ๊ฐ๋ค
3+ ์ค๊ฐ๊ฐ์ ๊ธฐ์ค๊ฐ์ผ๋ก ์ก๊ณ , ๋ง์ง๋ง ๊ฐ๋ณด๋ค ํฐ์ง ์์์ง ํ์ธํ๋ค
4+ ๊ธฐ์ค๊ฐ์ด ๋ง์ง๋ง ๊ฐ๋ณด๋ค ์์ ๊ฒฝ์ฐ, ์ต์๊ฐ์ ์ผ์ชฝ ๋ฐ์ชฝ์ ์๊ฑฐ๋ ๊ธฐ์ค๊ฐ์. ex) 5 1 2 3 4
5+ -> range๋ฅผ ์ผ์ชฝ ๋ฐ์ชฝ์ผ๋ก ์ค์ด๊ณ (๊ธฐ์ค๊ฐ ํฌํจ) ํด๋น ์ค๊ฐ๊ฐ์ ๊ธฐ์ค๊ฐ์ผ๋ก ์ก๋๋ค
6+ ๊ธฐ์ค๊ฐ์ด ๋ง์ง๋ง ๊ฐ๋ณด๋ค ํด ๊ฒฝ์ฐ, ์ต์๊ฐ์ ์ค๋ฅธ์ชฝ ๋ฐ์ชฝ์ ์์. ex) 3 4 5 1 2
7+ -> range๋ฅผ ์ค๋ฅธ์ชฝ ๋ฐ์ชฝ์ผ๋ก ์ค์ด๊ณ ํด๋น ์ค๊ฐ๊ฐ์ ๊ธฐ์ค๊ฐ์ผ๋ก ์ก๋๋ค
8+
9+ ์ต์ข
์ ์ผ๋ก start, end๊ฐ ๊ฐ์์ง๋ ๊ฐ์ด ์ต์๊ฐ์ด ๋๋ค.
10+
11+ ์๊ฐ๋ณต์ก๋ : O(LogN) -> N์ nums์ ๊ฐ์. ์ด๋ถํ์
12+ */
13+
14+ function findMin ( nums : number [ ] ) : number {
15+ let start = 0
16+ let end = nums . length - 1
17+
18+ while ( start < end ) {
19+ let target = Math . floor ( ( start + end ) / 2 )
20+ if ( nums [ target ] < nums [ end ] ) {
21+ end = target
22+ } else {
23+ start = target + 1
24+ }
25+ }
26+
27+ return nums [ start ]
28+ }
You canโt perform that action at this time.
0 commit comments