Skip to content

[201411108] WEEK 02 Solutions - #2936

Open
201411108 wants to merge 9 commits into
DaleStudy:mainfrom
201411108:week-02
Open

201411108 wants to merge 9 commits into
DaleStudy:mainfrom
201411108:week-02

Conversation

@201411108

@201411108 201411108 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI 리뷰(알고리즘 패턴, 시간/공간 복잡도, 학습 현황) 결과는 Checks 탭에서 볼 수 있어요.

Comment thread valid-anagram/201411108.py Outdated
Comment on lines +9 to +14
if target_char in converted_dict:
converted_dict[target_char] += 1
else:
converted_dict[target_char] = 1

return converted_dict

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

안녕하세요 @201411108 님:)
9-12줄은 converted_dict[target_char] += 1로 줄일 수 있을 것 같습니다

@201411108 201411108 Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

defaultdict에서는 키가 없을경우 1로 바꿔줘야 한다고 생각했는데 초깃값이 0이니까 괜찮겠네요. 감사합니다!
제가 다른분께 관련된 리뷰를 드렸던 걸로 기억하고 있는데 저도 잘못 쓴걸 보면 잘 모르고 쓰고 있다는 생각이 들어서 부끄럽네요 ㅎㅎ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

앗 지난주차에 제게 남겨주셨습니다 ㅎㅎ
그래서인지 이번 풀이에서 어떻게 활용되는지 더 유심히 보게 됐던 것 같아요!
덕분에 저도 defaultdict(int)는 없는 key에 접근하면 0에서 시작하여 += 1로 첫 값이 1이 된다는 걸 확실히 짚고 갑니다~!

Comment thread valid-anagram/201411108.py Outdated
Comment on lines +25 to +32
if len(s_dict.keys()) != len(t_dict.keys()):
return False

for key in s_dict:
if s_dict[key] != t_dict[key]:
return False

return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return s_dict==t_dict로 한번에 바꿀 수 있을 듯 하네요!
dict가 같다는 것은 key와 대응되는 value가 모두 동일해서 더 간단하게 줄일 수 있을 것 같습니다🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

오, 파이썬에서는 이렇게 자료형 비교가 되는군요! 새로운 내용을 배웠습니다. 감사합니다.

@wlghsp
wlghsp self-requested a review November 17, 2026 08:48
Comment thread 3sum/201411108.py
Comment on lines +10 to +11
sorted_nums = nums[:]
sorted_nums.sort()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

10번 줄에서 nums[:]로 copy하고 정렬하신 이유가 궁금합니다..!! 원본 배열을 살리기 위함인가요.?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

네 맞습니다. 파이썬에서 sort 함수는 새로운 리스트를 반환하지 않고 함수를 호출한 리스트를 정렬합니다.
이렇게 될 경우 threeSum 함수를 호출한 쪽에서 인자를 넘겨준 리스트도 함께 정렬되게 되는데 이 부분이 의도치 않은 변경, 그러니까 side effect를 발생시킬 수 있다고 생각했습니다.
알고리즘 문제를 풀면서 고려할 사항까지는 아니지만 평소에 습관을 들여두는게 안정적인 코드를 작성할 수 있다고 생각하여 넣게 되었습니다.

찾아보니까 sorted 함수를 사용하면 정렬된 새로운 리스트를 받을 수 있다고 하더라고요! 덕분에 새롭게 알게 되었습니다!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

제 단순한 궁금증으로 여쭤본 건데, side effect까지 고려하신 거였군요!
호출한 쪽의 원본 리스트가 바뀔 수 있다는 차이를 배워 갑니다..
지난 주차 때도 느꼈지만, 비단 이 문제를 해결하는 코드에 그치지 않고 다른 상황에서도 stable하게 동작할지까지 생각하시는 것 같아서 정말 많이 배워 가네요..! 감사합니다

Comment thread 3sum/201411108.py
Comment on lines +31 to +34
while left < right and sorted_nums[left] == sorted_nums[left + 1]:
left += 1
while left < right and sorted_nums[right] == sorted_nums[right - 1]:
right -= 1

@Chaewon-Park-STUDY Chaewon-Park-STUDY Nov 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

저도 비슷한 흐름으로 풀었는데, answer = set()으로 두고 저는 풀었네요..
31-34번 줄에서 동일 값은 skip하여 중복 조합이 아예 안 생기니 list로 충분하네요~! 🙂


climb_ways = [0 for _ in range(n + 1)]

climb_ways[0] = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

이 부분은 계단을 아예 오르지 않는 경우의 수는 0임을 명시해주고자 작성하신 것일까요..?🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

파이썬은 문자열에 sorted 를 쓸수 있죠!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Solving

Development

Successfully merging this pull request may close these issues.

3 participants