Skip to content

Commit

Permalink
Merge pull request #979 from anniemon/main
Browse files Browse the repository at this point in the history
[anniemon78] Week8
  • Loading branch information
TonyKim9401 authored Feb 2, 2025
2 parents b63432b + bf8f275 commit f2b9477
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions longest-common-subsequence/anniemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* ์‹œ๊ฐ„ ๋ณต์žก๋„:
* text1๊ณผ text2์˜ ๊ธธ์ด๋กœ ๊ตฌ์„ฑ๋œ 2์ฐจ์› ๋งคํŠธ๋ฆญ์Šค๋ฅผ ์ˆœํšŒํ•˜๋ฏ€๋กœ,
* text1์˜ ๊ธธ์ด๋ฅผ n, text2์˜ ๊ธธ์ด๋ฅผ m์ด๋ผ๊ณ  ํ•˜๋ฉด O(m*n)
* ๊ณต๊ฐ„ ๋ณต์žก๋„:
* text1๊ณผ text2์˜ ๊ธธ์ด๋กœ ๊ตฌ์„ฑ๋œ 2์ฐจ์› ๋งคํŠธ๋ฆญ์Šค๋ฅผ ์ƒ์„ฑํ•˜๋ฏ€๋กœ, O(m*n)
*/
/**
* @param {string} text1
* @param {string} text2
* @return {number}
*/
var longestCommonSubsequence = function(text1, text2) {
const dp = new Array(text1.length+1).fill(0).map(e => new Array(text2.length+1).fill(0));
for(let i = text1.length -1; i >= 0; i--) {
for(let j = text2.length-1; j >=0; j--) {
if(text1[i] === text2[j]) {
dp[i][j] = dp[i+1][j+1] + 1
} else {
dp[i][j] = Math.max(dp[i+1][j], dp[i][j+1])
}
}
}
return dp[0][0]
};
16 changes: 16 additions & 0 deletions number-of-1-bits/anniemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* ์‹œ๊ฐ„ ๋ณต์žก๋„: n์„ ๋‚˜๋ˆ„๋Š” ํšŸ์ˆ˜๋Š” n์˜ ๋น„ํŠธ ์ˆ˜์— ๋น„๋ก€ํ•˜๋ฏ€๋กœ, O(log n)
* ๊ณต๊ฐ„ ๋ณต์žก๋„: ๋น„ํŠธ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋„ n์˜ ๋น„ํŠธ ์ˆ˜์— ๋น„๋ก€ํ•˜๋ฏ€๋กœ, O(log n)
*/
/**
* @param {number} n
* @return {number}
*/
var hammingWeight = function(n) {
let bi = '';
while(n / 2 > 0) {
bi += (n % 2).toString();
n = Math.floor(n / 2)
}
return (bi.match(/1/g) || []).length
};

0 comments on commit f2b9477

Please sign in to comment.