Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BumbuShoji
Copy link
Owner

Comment on lines +21 to +22
- 空間計算量 0(n+m)
- 最大の大きさn,mのsetを作るから

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)

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):
Copy link

Choose a reason for hiding this comment

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

これ、どっちがいいんですかね。

大きい方を set で変換して、小さい方を iter で舐めるというコードですが、舐める方が簡単で速そうな気がするのでそっちのほうが大きいほうがよいのではないでしょうか。

Python で速度の話は、(そもそもインタープリターのオーバーヘッドが大きいので)結構不毛なことになる気はしています。

Copy link
Owner Author

Choose a reason for hiding this comment

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

なるほど。

計算量のことを考えてみてというコメントをいただいてから速度について考えるようになったのですが、このレベルの細かい話をしたいならC++とかjavaで書いた方がいいんですかね?

Copy link

@colorbox colorbox left a comment

Choose a reason for hiding this comment

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

だいたい良さそうに思いました

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants