-
-
Notifications
You must be signed in to change notification settings - Fork 195
[TONY] WEEK 03 Solutions #374
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
Conversation
if (n >= 1) dp[1] = 1; | ||
if (n >= 2) dp[2] = 2; |
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.
n 이 1 또는 2 일 때는 아래 반복문을 수행하지 않아서 if 조건이 없어도 될 것 같아요!
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.
아 지금 보니 인덱스 처리때문에 추가하신 거군요
그럼에도 문제에서 n 은 1 이상이라고 했으니, if 조건은 2에만 있어도 될 것 같네요!
// time complexity: O(n); | ||
// space complexity: O(n); |
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.
(사소) Python
에서는 주석을 메서드 내부에 쓰긴 하나, Java
에서는 이렇게 작성하는 건 많이 보지 못했습니다 (물론 주석 바로 아래 코드에 대해 주석이 필요할 때는 작성하겠지만 요건 그 경우는 아닌 것 같군요 ㅎㅎㅎ) 주석을 메서드 또는 클래스 위로 옮겨주시면 어떨까요?
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.
@bky373 다음주부터 적용하도록 하겠습니다 감사합니다!
// time complexity: O(n); | ||
// space complexity: O(n); | ||
Map<Integer, Integer> map = new HashMap<>(); | ||
for (int i = 0; i < nums.length; i++) map.put(nums[i], i); |
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.
시간 복잡도는 동일하지만 for 문을 한 번 사용하는 것으로 문제를 해결할 수 있습니다!
코드를 바꿔달라고 말씀드리는 건 아니고 나중에 시간되실 때 확인 한 번 해보시면 좋을 것 같습니다~
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.
답안 코드 일찍 제출해주셔서 감사합니다. 승인 여부에 지장을 주지 않는 한 가지 질문을 남겼습니다.
@@ -0,0 +1,23 @@ | |||
class Solution { | |||
// time complexity: O(2^n); | |||
// space complecity: O(n*m); |
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.
어떻게 공간 복잡도가 O(n * m)
이 나오셨는지 궁금합니다!
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.
어떻게 공간 복잡도가
O(n * m)
이 나오셨는지 궁금합니다!
(공간 복잡도에 더해 ㅎㅎ..) 재귀가 사용 됐을 때 시간 복잡도를 어떻게 판단하시는지 과정이 궁금합니다..!
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.
@DaleSeo @taekwon-dev 정정하겠습니다!
시간 복잡도: O(2^n * m)
- 같은 숫자 반속 가능성과 주어진 배열의 길이
공간 복잡도: O(n * m)
- 가능한 조합의 수와 가능한 조합의 길이
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.
@TonyKim9401 저는 공간 복잡도에서 의문을 제기했는데, 시간 복잡도를 정정해주셨네요 ㅋㅋ 😵
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.
고생 하셨습니다!
체크 리스트
In Review
로 설정해주세요.