-
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
[haklee] week 2 #342
[haklee] week 2 #342
Conversation
코드를 전반적으로 엄청 깔끔하게 잘 쓰시네요! 많이 배우고갑니다 고생하셨어요! |
class Solution: | ||
def numDecodings(self, s: str) -> int: | ||
# init | ||
x, y = 1, int(int(s[-1]) != 0) # f(0), f(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.
여기서 y 값을 굳이 int로 한번더 캐스팅 해주신거는 확실하게 만들고 가시려고 한걸까요? 궁금해서 한 번 돌려보고 왔는데 boolean으로 반환시켜도 파이썬 내부에서는 int로 처리하는거 같아서요 😄
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.
앞서 설명한 이유로 int로 만들지 않아도 코드는 잘 돌았을텐데, 중간에 디버깅 하려고 x, y값을 출력해보다가 숫자들 사이에 True가 박혀있는 것을 보고 매우 분노하여 곧장 int로 만들어버렸습니다...
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.
고수의 향기를 맡고 갑니다 ㅋㅋ 👃
""" | ||
@param: strs: a list of strings | ||
@return: encodes a list of strings to a single string. | ||
""" | ||
|
||
def encode(self, strs): | ||
body = "".join(strs) | ||
header = ",".join([str(len(i)) for i in strs]) | ||
return header + ":" + body | ||
|
||
""" | ||
@param: str: A string | ||
@return: decodes a single string to a list of strings | ||
""" | ||
|
||
def decode(self, str): | ||
header, body = str.split(":", 1) | ||
len_list = [int(i) for i in header.split(",")] | ||
start_ind = 0 | ||
result = [] | ||
for i in len_list: | ||
result.append(body[start_ind : start_ind + i]) | ||
start_ind += i | ||
return result |
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.
오오 넵 좋습니다!
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.
haklee님 완풀 고생하셨습니다 :)
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
# return sorted(s) == sorted(t) # TC: O(n log n), SC: O(n) | ||
return Counter(s) == Counter(t) # TC: O(n), SC: O(n) |
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.
파이썬에서는 테이블(딕셔너리)을 비교하는 메서드가 존재하는군요
# self.right = right | ||
class Solution: | ||
def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]: | ||
inorder_indices = {v: i for i, v in enumerate(inorder)} |
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.
hash table을 사용해서 노드의 순서로 정렬하는 방법이 있군요👍
- 0, 1의 bit_count가 [0, 1]이라면, 2, 3의 bit_count는 [0+1, 1+1], 즉, 0~3의 bit_count는 [0, 1, 1, 2] | ||
- 0~3의 bit_count가 [0, 1, 1, 2]라면, 4~7의 bit_count는 [1, 2, 2, 3], 즉, 0~7의 bit_count는 |
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.
문제를 정확히 이해하고 있다고 느껴지는 testcase인데요? 너무 좋습니다 :)
No description provided.