-
-
Notifications
You must be signed in to change notification settings - Fork 267
[ys-han00] WEEK 01 solutions #1973
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
base: main
Are you sure you want to change the base?
Conversation
|
Add Project Week 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.
| sort(nums.begin(), nums.end()); | ||
|
|
||
| for(int i = 0; i < nums.size() - 1; i++) | ||
| if(nums[i] == nums[i+1]) | ||
| return true; | ||
|
|
||
| return false; |
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.
아래와 같은 로직으로 이해했는데 제가 잘 이해한것이 맞을까요?
- 배열
nums를 정렬한 다음 - 배열의 크기만큼 반복문을 돌면서
- 배열의 다음 요소와 같은 값이 있는지를 판단한다
로직이 명확하고 직관적이네요 👍
💡 참고: 다른 접근 방법
주석으로 남겨주신 첫 시도를 보니 이미 해싱 아이디어를 생각하셨던 것 같아요.
다만 배열 대신 unordered_set을 활용하면 시간과 메모리 문제를 해결할 수 있을 것 같아요!
unordered_set 을 이용하면 실제 등장한 숫자만 저장하기 때문에 메모리 효율적으로 동작할 수 있을 것 같아요.
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.
아래와 같은 로직으로 이해했는데 제가 잘 이해한것이 맞을까요? 1. 배열
nums를 정렬한 다음 2. 배열의 크기만큼 반복문을 돌면서 3. 배열의 다음 요소와 같은 값이 있는지를 판단한다 ...
네 맞게 이해하셨습니다! 간단하면서도 시간효율이 제일 좋아서 채택한 풀이입니다.
...
unordered_set을 이용하면 실제 등장한 숫자만 저장하기 때문에 메모리 효율적으로 동작할 수 있을 것 같아요.
코드에는 포함되지 않았지만, 말씀하신 unordered_set 을 사용해서도 풀어봤습니다. 예상하신대로 문제 없이 동작합니다! 하지만, 시간, 메모리 효율이 제출한 코드 보다 좋지 않아 코드에 포함하지 않았습니다 ㅎㅎ
| sort(num_idx.begin(), num_idx.end()); | ||
|
|
||
| int left = 0, right = nums.size() - 1; | ||
| while(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.
💡 참고 사항
문제에서 답이 반드시 존재한다고 명시되어 있어서 while(1)도 괜찮지만
더 안전한 코드를 위해 while(left < right)로 작성하는 것도 방법입니다 👍
while(left < right) { // 명확하게 조건을 명시
// ...
}이렇게 명시적으로 처리하면 혹시 모를 예외 상황(답이 없는 경우)에서 무한 루프를 방지할 수 있습니다.
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.
더 안전한 코드를 위해
while(left < right)로 작성하는 것도 방법입니다 👍
...
의견 감사합니다! 알고리즘 문제 풀 때 습관인데, 이번 스터디 때 고치도록 해보겠습니다 ㅎㅎ
안녕하세요~! 부끄럽게도 깃을 사용한 협업 경험이 없어서 제 첫 깃 리뷰어십니다 :) PR도 처음이라, 이것저것 해보다가 실수가 많아 힘든 하루였네요 ㅎㅎ 먼저, 작성해주신 리뷰에 대해 답변 달았는데, 실수가 많았아서 잘한지 모르겠네요 ㅜㅜ 추가적으로 푼 문제들과 혹시나 깃 사용 관련해서도 의견이 있으시면 언제든지 의견주세요! 감사합니다. |
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!