-
-
Notifications
You must be signed in to change notification settings - Fork 304
[prgmr99] WEEK 02 solutions #2034
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,23 @@ | ||
| /** | ||
| * @param {number} n | ||
| * @return {number} | ||
| */ | ||
| var climbStairs = function (n) { | ||
| const memo = {}; | ||
|
|
||
| function fibo(num, memo) { | ||
| if (num === 1) return 1; | ||
| if (num === 2) return 2; | ||
|
|
||
| if (memo[num]) { | ||
| return memo[num]; | ||
| } | ||
|
|
||
| const result = fibo(num - 1, memo) + fibo(num - 2, memo); | ||
|
Contributor
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. 재귀가 아닌 반복문을 이용한다면 call stack과 |
||
| memo[num] = result; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| return fibo(n, memo); | ||
| }; | ||
This file contains hidden or 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,33 @@ | ||
| /** | ||
| * @param {string} s | ||
| * @param {string} t | ||
| * @return {boolean} | ||
| */ | ||
| var isAnagram = function (s, t) { | ||
| const stringMap = new Map(); | ||
|
|
||
| if (s.length !== t.length) return false; | ||
|
|
||
| for (let i = 0; i < s.length; i++) { | ||
| const currentValue = stringMap.get(s[i]); | ||
|
|
||
| if (currentValue) { | ||
| stringMap.set(s[i], currentValue + 1); | ||
| } else { | ||
| stringMap.set(s[i], 1); | ||
| } | ||
| } | ||
|
|
||
| for (let i = 0; i < t.length; i++) { | ||
| const currentValue = t[i]; | ||
| const currentValueInStringMap = stringMap.get(currentValue); | ||
|
|
||
| if (currentValueInStringMap) { | ||
| stringMap.set(currentValue, currentValueInStringMap - 1); | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| }; |
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.
클로저 내부에서는
memo에 접근할 수 있으므로fibo의 파라미터로memo를 넘길 필요가 없을 것 같습니다!