File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
longest-common-subsequence Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * ์๊ฐ ๋ณต์ก๋:
3+ * text1๊ณผ text2์ ๊ธธ์ด๋ก ๊ตฌ์ฑ๋ 2์ฐจ์ ๋งคํธ๋ฆญ์ค๋ฅผ ์ํํ๋ฏ๋ก,
4+ * text1์ ๊ธธ์ด๋ฅผ n, text2์ ๊ธธ์ด๋ฅผ m์ด๋ผ๊ณ ํ๋ฉด O(m*n)
5+ * ๊ณต๊ฐ ๋ณต์ก๋:
6+ * text1๊ณผ text2์ ๊ธธ์ด๋ก ๊ตฌ์ฑ๋ 2์ฐจ์ ๋งคํธ๋ฆญ์ค๋ฅผ ์์ฑํ๋ฏ๋ก, O(m*n)
7+ */
8+ /**
9+ * @param {string } text1
10+ * @param {string } text2
11+ * @return {number }
12+ */
13+ var longestCommonSubsequence = function ( text1 , text2 ) {
14+ const dp = new Array ( text1 . length + 1 ) . fill ( 0 ) . map ( e => new Array ( text2 . length + 1 ) . fill ( 0 ) ) ;
15+ for ( let i = text1 . length - 1 ; i >= 0 ; i -- ) {
16+ for ( let j = text2 . length - 1 ; j >= 0 ; j -- ) {
17+ if ( text1 [ i ] === text2 [ j ] ) {
18+ dp [ i ] [ j ] = dp [ i + 1 ] [ j + 1 ] + 1
19+ } else {
20+ dp [ i ] [ j ] = Math . max ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )
21+ }
22+ }
23+ }
24+ return dp [ 0 ] [ 0 ]
25+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * ์๊ฐ ๋ณต์ก๋: n์ ๋๋๋ ํ์๋ n์ ๋นํธ ์์ ๋น๋กํ๋ฏ๋ก, O(log n)
3+ * ๊ณต๊ฐ ๋ณต์ก๋: ๋นํธ ๋ฌธ์์ด์ ๊ธธ์ด๋ n์ ๋นํธ ์์ ๋น๋กํ๋ฏ๋ก, O(log n)
4+ */
5+ /**
6+ * @param {number } n
7+ * @return {number }
8+ */
9+ var hammingWeight = function ( n ) {
10+ let bi = '' ;
11+ while ( n / 2 > 0 ) {
12+ bi += ( n % 2 ) . toString ( ) ;
13+ n = Math . floor ( n / 2 )
14+ }
15+ return ( bi . match ( / 1 / g) || [ ] ) . length
16+ } ;
You canโt perform that action at this time.
0 commit comments