Skip to content

[anniemon78] Week8 #979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};