Open
Conversation
oda
reviewed
Jan 11, 2026
| // | ||
| // https://discord.com/channels/1084280443945353267/1233603535862628432/1238208008182562927 | ||
| // 不変条件を意識するのは大事。LinkedHashMap があれば、一つ気にしなければいけない要素を減らせる。 | ||
| // Dart の Map はデフォルトで LinkedHashMap になっているらしい。 |
There was a problem hiding this comment.
Java の LinkedHashMap は、要するに LinkedList + HashMap というデータ構造ですが、取り除くのは後でもいいので Queue と HashMap でもいけるという感じですね。
| // 自分は Set を用いて重複を判定していたが、counter での重複の方がコードが簡潔に済んで良い。 | ||
| // | ||
| // https://github.com/t0hsumi/leetcode/pull/15#discussion_r1930362913 | ||
| // 重複がないことの証明として、「左から読んだときと右から読んだときで、添字が変わらない」ことを使っていた。 |
There was a problem hiding this comment.
Python とかだと、文字を探すのはネイティブコードで走るので何度も走査していてもそこそこ速いと思います。
mamo3gr
reviewed
Jan 11, 2026
| var counter = <String, int>{}; | ||
|
|
||
| for (var i = 0; i < s.length; i++) { | ||
| counter[s[i]] = (counter[s[i]] ?? 0) + 1; |
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/first-unique-character-in-a-string/
次に解く問題:https://leetcode.com/problems/subarray-sum-equals-k/description/