Open
Conversation
ksaito0629
reviewed
Mar 3, 2026
Comment on lines
+3
to
+8
| if len(nums1) < len(nums2): | ||
| smaller_nums = nums1 | ||
| larger_nums = nums2 | ||
| else: | ||
| smaller_nums = nums2 | ||
| larger_nums = nums1 |
There was a problem hiding this comment.
配列の大きさを命名で明示的にしないでよいならば、
if len(nums1) > len(nums2):
nums1, nums2 = nums2, nums1
で済みますね
Comment on lines
+15
to
+19
| result_set = set() | ||
| for num in larger_nums: | ||
| if num not in exist_in_smaller: | ||
| continue | ||
| result_set.add(num) |
There was a problem hiding this comment.
result は hash set を使わずにも書けます。
hash set の remove, discard が使えます。
https://docs.python.org/3.14/library/stdtypes.html#set.remove
Comment on lines
+114
to
+116
| exist_in_smaller = set() | ||
| for num in smaller_nums: | ||
| exist_in_smaller.add(num) |
There was a problem hiding this comment.
exist_in_smaller = set(smaller_nums) と書けますね。
nodchip
reviewed
Mar 4, 2026
| exist_in_smaller = set(smaller_nums) | ||
| exist_in_larger = set(larger_nums) | ||
|
|
||
| result = exist_in_smaller.intersection(exist_in_larger) |
There was a problem hiding this comment.
exist_in_smaller & exist_in_larger と書いたほうがシンプルだと思います。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/intersection-of-two-arrays/description/