Skip to content
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

[HodaeSsi] Week 5 #883

Merged
merged 5 commits into from
Jan 12, 2025
Merged

[HodaeSsi] Week 5 #883

merged 5 commits into from
Jan 12, 2025

Conversation

HodaeSsi
Copy link
Contributor

답안 제출 문제

체크 리스트

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

Copy link
Contributor

@EgonD3V EgonD3V left a comment

Choose a reason for hiding this comment

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

이번 주도 수고많으셨습니다. 다음 주도 화이팅!

Comment on lines +4 to +12
def maxProfit(self, prices: List[int]) -> int:
min_price = float('inf')
max_profit = 0

for price in prices:
min_price = min(min_price, price)
max_profit = max(max_profit, price - min_price)

return max_profit
Copy link
Contributor

Choose a reason for hiding this comment

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

알고리즘이 간결하고 이쁘네요. 다만 가독성을 위해 indent는 4space를 추천드립니다.

Comment on lines +3 to +6

class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = collections.defaultdict(list)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = collections.defaultdict(list)
from collections import defaultdict
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = defaultdict(list)

파이썬에서 보통은 이런 식으로 모듈을 import 하는데, 이러면 어떤 모듈을 사용하는 파일인지 알기 쉬워져서 가독성이 더 좋아질 것 같습니다

def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = collections.defaultdict(list)
for word in strs:
anagrams[''.join(sorted(word))].append(word)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
anagrams[''.join(sorted(word))].append(word)
key = ''.join(sorted(word))
anagrams[key].append(word)

코딩 골프 느낌의 pythonic한 짧은 코드도 좋지만, 해당 임시 변수가 어떤 역할을 하는지 선언한 변수명으로 알려주면 좋을 것 같습니다.

# 시간복잡도 : O(n^2)
# 공간복잡도 : O(n)
class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

사실 이 문제는 위의 implement-trie-prefix-tree와 연관되어 있어서 이를 활용하여 풀어보시면 도움이 되실 것 같습니다

@TonyKim9401 TonyKim9401 merged commit e537a6e into DaleStudy:main Jan 12, 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.

3 participants