-
Notifications
You must be signed in to change notification settings - Fork 0
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
Intersection of Two Arrays step1-3 #14
base: main
Are you sure you want to change the base?
Conversation
- 空間計算量 0(n+m) | ||
- 最大の大きさn,mのsetを作るから |
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.
set(nums1)の空間計算量としては、len(nums1)というより、nums1の文字の種類数によって決まると思いました。
仮に文字種をアルファベットに限定すると定数になるので、結果として空間計算量はO(1)になるのでは?と考えています。
colorbox/leetcode#29 (comment)
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.
すみません、別の問題と間違えていました!空間計算量はO(n+m)であってると思います
```python | ||
class Solution(): | ||
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: | ||
if len(nums1) > len(nums2): |
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.
これ、どっちがいいんですかね。
大きい方を set で変換して、小さい方を iter で舐めるというコードですが、舐める方が簡単で速そうな気がするのでそっちのほうが大きいほうがよいのではないでしょうか。
Python で速度の話は、(そもそもインタープリターのオーバーヘッドが大きいので)結構不毛なことになる気はしています。
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.
なるほど。
計算量のことを考えてみてというコメントをいただいてから速度について考えるようになったのですが、このレベルの細かい話をしたいならC++とかjavaで書いた方がいいんですかね?
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.
だいたい良さそうに思いました
問題:
https://leetcode.com/problems/intersection-of-two-arrays/description/