-
-
Notifications
You must be signed in to change notification settings - Fork 195
[bhyun-kim.py, 김병현] Week 7 Solutions #130
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
Conversation
|
||
dummy_node = ListNode() | ||
tail = dummy_node | ||
_n = len(vals) - 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.
여기서 변수명을 _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.
여기서 변수명을 _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.
네 함수 내부에서 일시적으로 쓰이는 변수의 경우 '_n'의 형태로 자주 쓰이는 걸로 알고 있는데요.
코딩 인터뷰 상황에서는 이 변수의 용도를 직접적으로 설명하는 변수명을 사용하는게 좀 더 좋지 않을까 생각합니다.
인터뷰어가 한 눈에 알 수 있고, 인터뷰이도 좀 더 직관적으로 설명할 수 있을 것 같아요.
예를 들어 위와 같은 경우에는
targetIndex = len(vals) - n
indexToRemove = len(vals) - 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.
피드백 감사드려요! 확실히 이렇게 바꾸면 설명과 이해에 더 도움이 되겠네요. 반영해서 commit 했습니다.
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.
문법상 어쩔 수 없이 선언하지만, 사용하지 않을 변수일 때 간혹 _
을 붙이기도 하더라구요!
for idx, val := range arr
에서, idx를 안쓰고 싶다하면 for _, val := range arr
이렇게요!!
TMI) GoLang에서는 사용하지 않는 변수가 있다면 컴파일 에러가 나옵니당..
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.
이번 주도 수고하셨어요!
영어로 풀이까지 적으시는 것 대단하십니당~
if root.left is not None: | ||
if root.val <= root.left.val: | ||
return False | ||
if not minimum < root.left.val < maximum: | ||
return False | ||
|
||
if root.right is not None: | ||
if root.val >= root.right.val: | ||
return False | ||
if not minimum < root.right.val < maximum: | ||
return False |
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.
저도 비슷한 방식으로 풀었었는데요!
해당 함수에서 root.left
, root.right
의 범위 검사 대신 root
의 범위를 검사하고, 자식들의 범위 검사는 재귀호출로 위임하니 좀 더 깔끔해졌었어요!
제 코드 링크: 링크
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.
오 좋은 풀이 공유 감사드려요. 저도 유사하게 바꿔봤습니다. 확실히 코드가 더 깔끔하네요 ㅎㅎ
No description provided.