Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 15 additions & 0 deletions climbing-stairs/seungseung88.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 시간복잡도: O(n)
* - for문 O(n)
* 공간복잡도: O(n)
* - arr O(n)
*/
const climbStairs = (n) => {
const arr = [1, 2];

for (let i = 2; i < n; i += 1) {
arr[i] = arr[i - 1] + arr[i - 2];
}

return arr[n - 1];
};
24 changes: 24 additions & 0 deletions valid-anagram/seungseung88.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 시간복잡도: O(n)
* - 첫번째 for문 O(n)
* - 두번째 for문 최대 O(n)
* 공간복잡도: O(n)
* - count O(n)
*/

const isAnagram = (s, t) => {
if (s.length !== t.length) return false;

const count = {};

for (let i = 0; i < s.length; i += 1) {
count[s[i]] = (count[s[i]] || 0) + 1;
count[t[i]] = (count[t[i]] || 0) - 1;
}

for (const i of Object.values(count)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

for in 연산으로 바꾸셔서 Object.values 메소드 배열 생성으로 인한 비용을 줄여서 작성하시면 더 효율적일 거 같습니다!

if (i !== 0) return false;
}

return true;
};