-
Notifications
You must be signed in to change notification settings - Fork 125
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
[HodaeSsi] Week 5 #883
Conversation
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.
이번 주도 수고많으셨습니다. 다음 주도 화이팅!
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 |
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.
알고리즘이 간결하고 이쁘네요. 다만 가독성을 위해 indent는 4space를 추천드립니다.
|
||
class Solution: | ||
def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | ||
anagrams = collections.defaultdict(list) |
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.
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) |
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.
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: |
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.
사실 이 문제는 위의 implement-trie-prefix-tree와 연관되어 있어서 이를 활용하여 풀어보시면 도움이 되실 것 같습니다
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.