-
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
[bus710] Week 09 #984
[bus710] Week 09 #984
Conversation
문제 1을 두번 풀어 보았습니다. 첫번째 풀이가 성능이 너무 안 좋은 것 같아서, 두번째는 단순하게 루프에 돌려보았습니다. 암튼 간에, 시간/공간 복잡도는 둘 다 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.
안녕하세요, @bus710 님! 이번 리뷰는 조금 늦었습니다. 코멘트 몇 개 남겨 두었으니 시간되실 때 확인해주시면 좋을 것 같습니다. 이번주도 수고하셨습니다!
return false | ||
} | ||
m := map[*ListNode]int{} | ||
for head.Next != nil { |
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 문의 조건에 head.Next != nil
가 아닌 head != nil
로 하면, 31 번째 줄의 if 문이 필요없게 되어서 코드가 조금 더 깔끔해지지 않을까 생각이 들었습니다. 어떻게 생각하시나요?
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.
첫번째 조건은 사실 제출하면서 추가 된 에러를 핸들링하느라 붙였더니 그렇게 통합 될 수도 있을 것 같네요.
m := map[*ListNode]int{} | ||
for head.Next != nil { | ||
if _, ok := m[head]; !ok { | ||
m[head] = 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.
현재 선언해두신 m
은 key 의 존재 여부만 확인하면 되기 때문에 value 의 역할은 사실상 큰 의미가 없어 보입니다. 저는 go 언어를 잘알지는 못하지만, int
대신 struct{}
를 사용하면 별도의 메모리 공간 할당이 필요없다고 하더라구요. 즉, m := map[*ListNode]struct{}{}
게 m
의 타입을 변경할 수도 있을 것 같습니다. 물론, 그럼에도 메모리상 큰 차이는 없을 것 같습니다.
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.
오 저도 들어본 것 같은 얘기네요. 아마도 포인터로 다루기 때문에 구조체를 값으로 쓰면 공간이 덜 든다고 했던 것 같기도...
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.