Skip to content

349. Intersection of Two Arrays#13

Open
tom4649 wants to merge 1 commit intomainfrom
349.Intersection-of-Two-Arrays
Open

349. Intersection of Two Arrays#13
tom4649 wants to merge 1 commit intomainfrom
349.Intersection-of-Two-Arrays

Conversation

@tom4649
Copy link
Copy Markdown
Owner

@tom4649 tom4649 commented Mar 14, 2026

res = set()
for num in nums2:
if num_to_existance_in_nums1[num]:
res.add(num)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

num_to_existance_in_nums1[num] = False
すれば res はいきなり list にできますね。

class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
if len(nums1) > len(nums2):
return self.intersection(nums2, nums1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

私は、これは
nums1, nums2 = nums2, nums1
くらいにしますねえ。
https://discord.com/channels/1084280443945353267/1391962276122067044/1457227504270970952

(個人的な感覚として、スワップだけで再帰スタックを掘るのは少し重いです。)

Copy link
Copy Markdown
Owner Author

@tom4649 tom4649 Mar 14, 2026

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.

2 participants