Skip to content
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
17 changes: 17 additions & 0 deletions doitchuu/climbStairs.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오우 완전 깔끔하네요

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];
Copy link
Collaborator

Choose a reason for hiding this comment

The 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];
};
30 changes: 30 additions & 0 deletions doitchuu/longestPalindrome.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오우 저랑 생각이 같으셨군요!

Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
};