Skip to content

[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

Merged
merged 6 commits into from
Apr 5, 2025
Merged

Conversation

JANGSEYEONG
Copy link
Contributor

@JANGSEYEONG JANGSEYEONG commented Mar 31, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@YoungSeok-Choi YoungSeok-Choi self-requested a review April 3, 2025 00:47
// 배열 전체 돌면서 조건에 맞게 return 시키기 - O(n)
return nums.map((x, i) => {
// 0이 2개 이상이라면 무조건 0
if (zeros.size > 1) {
Copy link
Contributor

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을 돌지 않고 함수를 종료 할 수 있어보입니다!

Copy link
Contributor Author

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) 작업
Copy link
Contributor

Choose a reason for hiding this comment

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

O(n^2) 복잡도로는 시간초과가 나는지 궁금합니다..!

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

시간, 공간복잡도를 모두 잡은 코드네요 👍👍

@JANGSEYEONG JANGSEYEONG moved this from Solving to In Review in 리트코드 스터디 4기 Apr 5, 2025
@JANGSEYEONG JANGSEYEONG moved this from In Review to Completed in 리트코드 스터디 4기 Apr 5, 2025
@JANGSEYEONG JANGSEYEONG merged commit bace583 into DaleStudy:main Apr 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants