Conversation
|
コメントに書かれていることがしらなかったことが多く、大変勉強になりました🙏(ただの感想ですみません) |
nittoco
reviewed
Jun 10, 2024
|
|
||
| intersection_values = [] | ||
| for num2 in nums2: | ||
| if num2 in found and num2 not in intersection_values: |
There was a problem hiding this comment.
これってintersection_valuesのlistに対してinをやっていますが、listのinはO(n)なので遅かったりしないのでしょうか
Owner
Author
There was a problem hiding this comment.
確かにintersection_values = set()としても良かったのですが、
最終的にlistを返さなくてはならないのと、
1 <= nums1.length, nums2.length <= 1000
なので、そこまで気にしなくて良いのかなと考え、このような実装にしました。
Owner
Author
|
nittocoさん、いつも見て頂いて有難うございます! |
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/submissions/1283408941/