-
Notifications
You must be signed in to change notification settings - Fork 126
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
[mand2, yapp] week1 답안 제출 #43
Conversation
mand2
commented
May 2, 2024
- Contains Duplicate
- Valid Anagram
- Two Sum
- Valid Palindrome
- Best Time to Buy and Sell Stock
- [x] Contains Duplicate - [x] Valid Anagram - [x] Two Sum - [x] Valid Palindrome - [x] Best Time to Buy and Sell Stock
[mand2] week1 답안 제출
|
@mand2 님, 혹시 디스코드 서버에 가입하셨나요? "mand2"라는 유저 네임이 검색되지 않으서요. 다른 분들처럼 PR 제목에 디스코드 유저 네임을 적어주시면, GitHub 유저 네임과 매칭하기가 좀 편할 것 같습니다. |
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.
오답 코드가 하나 있는 것 같아서 피드백 드렸습니당!
valid-anagram/mand2.py
Outdated
word_counter = {} | ||
# s 문자열 분해 | ||
for alpha in s: | ||
# 초기화 | ||
if alpha not in word_counter: | ||
word_counter[alpha] = 0 | ||
word_counter[alpha] += 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.
word_counter = {} | |
# s 문자열 분해 | |
for alpha in s: | |
# 초기화 | |
if alpha not in word_counter: | |
word_counter[alpha] = 0 | |
word_counter[alpha] += 1 | |
word_counter = defaultdict(int) | |
# s 문자열 분해 | |
for alpha in s: | |
word_counter[alpha] += 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.
오 감사합니다~! 이 부분을 미처 생각 못했었네요
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.
defaultdict
모듈 없이도 get
메서드로 기본값을 설정해줄 수도 있기는 합니다. ㅎㅎ
원하시는 방법을 사용하시면 될 것 같아요.
word_counter = {}
for alpha in s:
word_counter[alpha] = word_counter.get(alpha, 0) + 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.
@WhiteHyun 다른 기능도 알려주셔서 감사합니다😊👍
two-sum/mand2.py
Outdated
|
||
for i, value in enumerate(nums): | ||
look = target_num - value | ||
print('look:', look) |
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.
print('look:', look) |
사소한 부분이지만 솔루션 제출하실 땐 print 는 빼도 좋지 않을까요?
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.
복붙하다가 같이 딸려 들어갔나봐요. 감사합니다 :)
- two-sum: 쓸모없는 로그 삭제 - anagram: - 초기화 수정 - 로직 추가
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.
.gitignore 삭제하였고, 피드백 주신 부분 반영했습니다 :)
valid-anagram/mand2.py
Outdated
word_counter = {} | ||
# s 문자열 분해 | ||
for alpha in s: | ||
# 초기화 | ||
if alpha not in word_counter: | ||
word_counter[alpha] = 0 | ||
word_counter[alpha] += 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.
오 감사합니다~! 이 부분을 미처 생각 못했었네요
two-sum/mand2.py
Outdated
|
||
for i, value in enumerate(nums): | ||
look = target_num - value | ||
print('look:', look) |
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.
복붙하다가 같이 딸려 들어갔나봐요. 감사합니다 :)
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.
피드백 반영해주셔서 감사합니다!