8000 [23-01-31] dain.py by da-in · Pull Request #28 · da-in/algorithm-study · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[23-01-31] dain.py #28

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

Merged
merged 3 commits into from
Jan 31, 2023
Merged

[23-01-31] dain.py #28

merged 3 commits into from
Jan 31, 2023

Conversation

da-in
Copy link
Owner
@da-in da-in commented Jan 30, 2023

PR Summary

  • 폰켓몬 | 종류의 수와 N/2 중 더 작은 것이 정답
  • 올바른 괄호 | 스택에 쌓으며 ( 다음 )가 들어갈 차례면 pop()
  • 같은 숫자는 싫어 | 스택에 가장 위 숫자와 다를 때에만 append()

ISSUE NUMBER

@@ -1 +1,2 @@

def solution(nums):
return min(len(nums) / 2, len(set(nums)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

min은 생각 못했는데 if else보다 오히려 가독성 좋은거 같아요!

@@ -1 +1,2 @@

def solution(nums):
return min(len(nums) / 2, len(set(nums)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

min을 사용하면 시간복잡도 O(n)이 추가되긴 해요 하지만 가독성은 베스트

Copy link
Owner Author

Choose a reason for hiding this comment

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

위 코드에서 min()은 O(n)이아니라 O(2)의 상수시간!
그보다는 set(nums)로 set을 생성할 때 set의 길이만큼의 시간복잡도를 갖는다!😮

@da-in da-in merged commit 63f108e into main Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0