Skip to content

349. Intersection of Two Arrays#15

Open
TORUS0818 wants to merge 1 commit intomainfrom
349
Open

349. Intersection of Two Arrays#15
TORUS0818 wants to merge 1 commit intomainfrom
349

Conversation

@TORUS0818
Copy link
Copy Markdown
Owner

@nittoco
Copy link
Copy Markdown

nittoco commented Jun 10, 2024

コメントに書かれていることがしらなかったことが多く、大変勉強になりました🙏(ただの感想ですみません)


intersection_values = []
for num2 in nums2:
if num2 in found and num2 not in intersection_values:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

これってintersection_valuesのlistに対してinをやっていますが、listのinはO(n)なので遅かったりしないのでしょうか

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

確かにintersection_values = set()としても良かったのですが、
最終的にlistを返さなくてはならないのと、
1 <= nums1.length, nums2.length <= 1000
なので、そこまで気にしなくて良いのかなと考え、このような実装にしました。

@TORUS0818
Copy link
Copy Markdown
Owner Author

nittocoさん、いつも見て頂いて有難うございます!

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.

2 participants