Open
Conversation
Apo-Matchbox
reviewed
Dec 4, 2025
| continue | ||
| } | ||
|
|
||
| return [index, indexToFind] |
There was a problem hiding this comment.
好みの範囲かと思いますが、index[今みている要素], indexToFind[先に出てきた要素]で、読む人の脳内では、return [indexToFind, index]でもいいかと思いました。
oda
reviewed
Dec 6, 2025
| } | ||
| } | ||
|
|
||
| // それぞれの手法でかかる時間を計測してみた。 |
There was a problem hiding this comment.
こんなものかもしれないです。
もしも、調べたかったらでいいのですが、これ、どういう入力でやりましたか?
Owner
Author
There was a problem hiding this comment.
レビューありがとうございます。
入力については、nums は 0 ~ 100,000 の値からランダムに抽出を繰り返して作成し、target は、解が必ず存在するように、二つのインデックスを用意し、nums でそれらのインデックスの位置にある数字を足し合わせることで作成しました。具体的に入力を生成する関数としては、以下を使用しました。
func generateData(count: Int) -> (nums: [Int], target: Int) {
let nums = (0..<count).map { _ in Int.random(in: 0...100_000) }
let idx1 = Int.random(in: 0..<count)
var idx2 = Int.random(in: 0..<count)
while idx1 == idx2 { idx2 = Int.random(in: 0..<count) }
let target = nums[idx1] + nums[idx2]
return (nums, target)
}
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/two-sum/description/
次に解く問題:https://leetcode.com/problems/group-anagrams/description/