-
Notifications
You must be signed in to change notification settings - Fork 1
[WEEK 04-2] 추슬기 #13
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
[WEEK 04-2] 추슬기 #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @param {number} n | ||
| * @return {number} | ||
| */ | ||
| var climbStairs = function(n) { | ||
| const dp = [1, 2]; | ||
|
Collaborator
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. 오옷 이렇게 바로 집어넣을수도 있는데 전 생각 못하고 Array 생성하고 하나씩 넣었네요 알아갑니당!! |
||
|
|
||
| if (n === 1 || n === 2) { | ||
| return dp[n - 1]; | ||
| } | ||
|
|
||
| for (let i = 2; i < n; i++) { | ||
| dp[i] = dp[i - 2] + dp[i - 1]; | ||
| } | ||
|
|
||
| return dp[n - 1]; | ||
| }; | ||
|
Collaborator
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. 오우 저랑 생각이 같으셨군요!
Collaborator
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. Map으로 문자 빈도수를 세고, 짝수는 모두 사용 / 홀수는 하나 제외하고 사용한 뒤 마지막에 center 여부만 한 번 처리한 점이 좋은 것 같습니다 ㅎㅎ 다만 for (const [key, value] of map)에서 key를 사용하지 않으니 map.values()로 순회하면 조금 더 깔끔할 것 같아요! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * @param {string} s | ||
| * @return {number} | ||
| */ | ||
| var longestPalindrome = function(s) { | ||
| // 홀수는 1개만 사용 가능. | ||
| // 짝수갯수는 모두 사용 가능. | ||
| // 1개 이상의 홀수일 경우, 1개만 남기고 사용 가능 | ||
|
|
||
| // 1. 일단 갯수를 센다. (대, 소문자 구분) | ||
| // 2. 돌아가면서 전체 갯수를 카운트, 중간에 쓸 숫자가 있으면 count X | ||
| const map = new Map(); | ||
| let hasOdd = false; | ||
| let count = 0; | ||
|
|
||
| for (let i = 0; i < s.length; i++) { | ||
| map.set(s[i], (map.get(s[i]) || 0) + 1); | ||
| } | ||
|
|
||
| for (const [key, value] of map) { | ||
| if (value % 2 === 0) { | ||
| count += value; | ||
| } else { | ||
| count += value - 1; | ||
| hasOdd = true; | ||
| } | ||
| } | ||
|
|
||
| return hasOdd ? count + 1 : count; | ||
| }; |
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.
오우 완전 깔끔하네요