Skip to content

[이혜준] Week3 문제 풀이 #397

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 2 commits into from
Aug 31, 2024
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
28 changes: 28 additions & 0 deletions climbing-stairs/hyejjun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @param {number} n
* @return {number}
*/
var climbStairs = function (n) {
if (n <= 2) return n;

let first = 1;
let second = 2;

for (let i = 3; i <= n; i++) {
let third = first + second;
first = second;
second = third;
}

return second;
};

console.log(climbStairs(2));
console.log(climbStairs(3));
console.log(climbStairs(4));
console.log(climbStairs(5));

/*
시간 복잡도: O(n)
공간 복잡도: O(1)
*/
23 changes: 23 additions & 0 deletions two-sum/hyejjun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function (nums, target) {
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
return [i, j];
}
}
}
};
Comment on lines +6 to +14
Copy link
Contributor

Choose a reason for hiding this comment

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

안녕하세요! 적절한 자료구조를 활용해서 더 효율적인 방식으로 풀어볼 수 있을 것 같아요.
저는 이런 문제 풀 때 특히 주어진 배열의 원소를 꼭 다 활용하는 형태여야 하는가? 라는 질문을 스스로 던져보는데, 한 번 고민해보시면 좋을 것 같습니다.!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 의견 감사합니다. 자료구조 활용하는 방법을 고민해보겠습니다!


console.log(twoSum([2, 7, 11, 15], 9));
console.log(twoSum([3, 2, 4], 6));
console.log(twoSum([3, 3], 6));

/*
시간 복잡도: O(n^2)
공간 복잡도: O(1)
*/