-
Notifications
You must be signed in to change notification settings - Fork 126
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
[gomgom22] Week 2 #759
Merged
Merged
[gomgom22] Week 2 #759
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @description | ||
* 동적 프로그래밍(Dynamic Programming, DP)을 사용하여 계단을 오르는 방법 수를 계산합니다. | ||
* - 점화식: dp[i] = dp[i-1] + dp[i-2] | ||
* - dp[i-1]: 이전 계단에서 1단계 올라온 경우 | ||
* - dp[i-2]: 두 계단 아래에서 2단계 올라온 경우 | ||
* - 공간 최적화를 통해 배열 대신 두 변수(prev1, prev2)를 사용하여 메모리 사용량을 줄입니다. | ||
* @param {number}n step 수 | ||
* @returns {number} 계단 도달 방법 수 | ||
*/ | ||
function climbStairs(n: number): number { | ||
if (n <=2) return n; | ||
|
||
let prev2 = 1; // dp[i-2] | ||
let prev1 = 2; // dp[i-1] | ||
|
||
for (let i = 3; i <= n; i++) { | ||
const cur = prev1 + prev2; // dp[i] 계산 | ||
prev2 = prev1; // dp[i-2] 갱신 | ||
prev1 = cur; // dp[i-1] 갱신 | ||
} | ||
|
||
return prev1; // dp[n] 반환 | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* 두 문자열을 비교해서 Anagram 여부 확인 | ||
* - 시간 복잡도: O(n) | ||
* - 문자열 순회와 비교 과정을 포함하여 n은 문자열의 길이 | ||
* - 공간 복잡도: 0(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오탈자가 하나 있네요 ㅎㅎ |
||
* - 알파벳 개수가 26개로 고정 상수 공간 | ||
* @param {string} s - 문자열 s | ||
* @param {string} t - 문자열 t | ||
* @returns {boolean} - Anagram 여부 | ||
*/ | ||
function isAnagram(s: string, t: string): boolean { | ||
// 두 문열의 길이가 다른경우 false 반환 | ||
if (s.length !== t.length) { | ||
return false; | ||
} | ||
|
||
// 문자열 알파벳 사전을 위한 객체 선언 | ||
let vocabS = {}; | ||
let vocabT = {}; | ||
|
||
// s 문자열에 대한 알파벳 사전 생성 | ||
for (const char in s) { | ||
vocabS = vocabS[char] ? vocabS[char] + 1 : 1; | ||
}; | ||
|
||
// t 문자열에 대한 알파벳 사전 생성 | ||
for (const char in t) { | ||
vocabT = vocabT[char] ? vocabT[char] + 1 : 1; | ||
} | ||
|
||
|
||
// 두 문자열 사전을 비교하며 count 가 일치 하지 않은 경우 false 반환 | ||
for (const char in vocabS) { | ||
if (vocabS[char] !== vocabT[char]) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍