-
-
Notifications
You must be signed in to change notification settings - Fork 195
[JANGSEYEONG] WEEK 01 solutions #1162
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
// 배열 전체 돌면서 조건에 맞게 return 시키기 - O(n) | ||
return nums.map((x, i) => { | ||
// 0이 2개 이상이라면 무조건 0 | ||
if (zeros.size > 1) { |
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.
(이미 빠른 코드이지만) 전체곱을 구하는 reduce에서 0의 개수를 미리 카운트 해놓으면 0이 2개 이상인경우
map을 돌지 않고 함수를 종료 할 수 있어보입니다!
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개일 땐 위에서 미리 return 시켜도 무방한 코드인데 map 돌면서 조건 하나하나 분기하면서 생각하다보니 넣어버린 것 같습니다 ㅎㅎ.. 리뷰 감사합니다!
@@ -0,0 +1,42 @@ | |||
/* | |||
시간복잡도: O(n²) | |||
- nums.indexOf()는 배열 전체를 순회하는 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.
O(n^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.
리트코드에서는 시간 초과가 안납니다!
O(n²)일 떄: 75ms, O(n)일 때: 2ms 로 차이가 굉장히 많이 나는건 확인했습니다 ㅎ_ㅎ
문제 하단에 "Follow-up: Can you come up with an algorithm that is less than O(n2) time complexity?" 라고 되어있어서 더 줄여봤습니다!
var containsDuplicate = function (nums) { | ||
// Set으로 만들었을 때, 기존 배열과 사이즈가 다르면 중복이 제거된거임 | ||
const numsSet = new Set(nums); | ||
return nums.length !== numsSet.size; |
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
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!