Skip to content

[YOOHYOJEONG] WEEK 02 solutions#2400

Merged
YOOHYOJEONG merged 2 commits intoDaleStudy:mainfrom
YOOHYOJEONG:main
Mar 14, 2026
Merged

[YOOHYOJEONG] WEEK 02 solutions#2400
YOOHYOJEONG merged 2 commits intoDaleStudy:mainfrom
YOOHYOJEONG:main

Conversation

@YOOHYOJEONG
Copy link
Contributor

@YOOHYOJEONG YOOHYOJEONG commented Mar 9, 2026

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@YOOHYOJEONG YOOHYOJEONG moved this from Solving to In Review in 리트코드 스터디 7기 Mar 13, 2026
Copy link
Contributor

@dohyeon2 dohyeon2 left a comment

Choose a reason for hiding this comment

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

배운부분을 주석에 적는 부분도 인상적입니다.
어떤 고민을 가지고 접근하셨는지 알 수 있어서 흥미로웠습니다.
파이썬이 확실히 간단한 코드에 있어서는 가독성이 압도적이네요.


a, b = 1, 2
for i in range(3, n+1):
a, b = b, a+b
Copy link
Contributor

Choose a reason for hiding this comment

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

파이썬의 다중 할당이 편리하네요.

left *= nums[i]

right = 1
for i in range(n-1, -1, -1):
Copy link
Contributor

Choose a reason for hiding this comment

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

개인적으로는 for문 조건에서 감산하는 형태로 사용하는 걸 지양하는 편인데,
'몇번 반복하도록 되어있는가?'라는 측면에서 가독성이 조금 떨어진다고 생각하기때문입니다.
효정님은 어떻게 생각하시나요? ㅎㅎ 생각을 나누고 싶어 코멘트 남깁니다.

for i in range(n):
    idx = n - i
    output[idx] *= right
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

좋은 의견 감사합니다!!
오른쪽 누적곱을 계산하려고 역순으로 순회하면서 작성했는데 말씀해주신 것처럼 반복 횟수 관점에서는 가독성이 떨어질 수 있다는 점 공감합니다.

Python에서는 보통 reversed(range(n)) 같은 방식으로도 표현할 수 있을 것 같아서 그 부분도 한 번 고려해 볼 수 있을 것 같습니다!!


class Solution(object):
def isAnagram(self, s, t):
if sorted(s) == sorted(t):
Copy link
Contributor

Choose a reason for hiding this comment

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

sorted함수가 대부분의 언어에서 n log n 시간복잡도를 가지기 때문에,
보다 더 효율적인 방법(O(n))이 있을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hyeri0903 님 덕분에 Counter를 사용하면 정렬 없이 O(n) 시간복잡도로 해결할 수 있다는 점을 알게 되었습니다!!

두 분 모두 감사합니다!

@hyeri0903 hyeri0903 self-requested a review March 14, 2026 01:36

a, b = 1, 2
for i in range(3, n+1):
a, b = b, a+b
Copy link
Contributor

Choose a reason for hiding this comment

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

다른 변수를 할당하지 않고 이렇게도 풀이할 수 있군요 ㅎㅎ👍

def isAnagram(self, s, t):
if sorted(s) == sorted(t):
return True
else:
Copy link
Contributor

@hyeri0903 hyeri0903 Mar 14, 2026

Choose a reason for hiding this comment

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

if 구문을 사용하지 않고 한줄로 작성할수도 있을것 같네요!

return sorted(s) == sorted(t)

Counter 를 사용한다면 시간 복잡도를 O(n)으로 줄일 수 있을것 같습니다.

from collections import Counter

def isAnagram(self, s, t):
    return Counter(s) == Counter(t)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

정렬을 이용한 방식이 간단한 것 같아서 이렇게 풀었는데 말씀해주신 것처럼 Counter를 사용하면 O(n)으로 더 효율적으로 해결할 수 있을 것 같습니다!
또 return sorted(s) == sorted(t)처럼 더 간결하게 표현할 수도 있을 것 같습니다!

좋은 방법 공유해주셔서 감사합니다!

@hyeri0903
Copy link
Contributor

알고리즘을 깔끔하게 잘 푸시지만 솔루션 상단에 시간 복잡도, 공간 복잡도 그리고 간단한 풀이 방법을 주석으로 작성하고 풀이하면 더 좋을 것 같습니다! 다음주도 화이팅해요🙌

@YOOHYOJEONG YOOHYOJEONG merged commit a4cd75f into DaleStudy:main Mar 14, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 7기 Mar 14, 2026
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.

3 participants