File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
longest-increasing-subsequence Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ * ๋ฌธ์ ์ค๋ช
4+ * - Longest Increasing Subsequence(LIS)
5+ * - ์ต์ฅ ์ฆ๊ฐ ๋ถ๋ถ ์์ด
6+ *
7+ * ์์ด๋์ด
8+ * 1) Brute Force
9+ * - ์๊ฐ๋ณต์ก๋๊ฐ O(2^n)์ด๋ผ์ TLE(Time Limit Exceed) ๋ฐ์
10+ * - ๊ตฌํ์ backtracking์ผ๋ก ํด์ผํจ.
11+ *
12+ * 2) Dynamic Programming
13+ * - ์๊ฐ๋ณต์ก๋: O(n^2)
14+ * - nums[i]์ ์ด์ ์์๋ค ์ค ๊ฐ์ฅ ๊ธด LIS์ 1์ ๋ํด์ ์ ์ฅ
15+ *
16+ * 3) Binary Search
17+ * - ์๊ฐ ๋ณต์ก๋: (O(n log n))
18+ * - ๋ค์ ๊ธฐํ์ ํ์ด๋ด์ผ์ง..
19+ *
20+ */
21+ function lengthOfLIS ( nums : number [ ] ) : number {
22+ const dp = Array ( nums . length ) . fill ( 1 ) ;
23+
24+ for ( let i = 0 ; i < nums . length ; i ++ ) {
25+ for ( let j = 0 ; j < i ; j ++ ) {
26+ if ( nums [ j ] < nums [ i ] ) {
27+ dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;
28+ }
29+ }
30+ }
31+
32+ return Math . max ( ...dp ) ;
33+ }
You canโt perform that action at this time.
0 commit comments