Skip to content

[YeomChaeeun] Week 8 #966

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 1, 2025
Merged
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
24 changes: 24 additions & 0 deletions longest-common-subsequence/YeomChaeeun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 가장 긴 공통 부분 수열 구하기
* 알고리즘 복잡도
* - 시간 복잡도: O(m*n)
* - 공간 복잡도: O(m*n)
* @param text1
* @param text2
*/
function longestCommonSubsequence(text1: string, text2: string): number {
let dp: number[][] = Array(text1.length + 1).fill(0)
.map(() => Array(text2.length + 1).fill(0));

for(let i = 1; i <= text1.length; i++) {
for(let j = 1; j <= text2.length; j++) {
if(text1[i-1] === text2[j-1]) {
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[text1.length][text2.length];
}
17 changes: 17 additions & 0 deletions number-of-1-bits/YeomChaeeun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 10진수 n이 2진수일 때 1을 세기
* 알고리즘 복잡도
* - 시간 복잡도: O(logn)
* - 공간 복잡도: O(logn)
* @param n
*/
function hammingWeight(n: number): number {
let binary = "";

while(n > 0) {
binary = (n % 2) + binary;
n = Math.floor(n / 2);
}

return [...binary].filter(val => val === '1').length
}
17 changes: 17 additions & 0 deletions sum-of-two-integers/YeomChaeeun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 연산자 + 사용하지 않고 덧셈하기
* 알고리즘 복잡도
* - 시간 복잡도: O(logn) - 비트 수만큼 계산
* - 공간 복잡도: O(1)
* @param a
* @param b
*/
function getSum(a: number, b: number): number {
while(b !== 0) {
let carry = a & b; // and - 11 & 10 = 10
a = a ^ b; // xor - 11 ^ 10 = 01
b = carry << 1; // 100
}

return a
}