347. Top K Frequent Elements#10
Open
tNita wants to merge 1 commit into
Open
Conversation
oda
reviewed
Feb 8, 2026
| - クイックソートはin-placeのソートなので空間計算量O(n)のマージソートよりメモリ使用量は小さい | ||
| - 実用面ではクイックソートの方が早いことが多いらしい | ||
| - https://stackoverflow.com/questions/70402/why-is-quicksort-better-than-mergesort | ||
| - クイックソートはin-placeのソートなのでアクセスするデータが局所的→PUのキャッシュに乗りやすくて早い?(理解怪しい) |
There was a problem hiding this comment.
ハードディスク上だとクイックソートはとても遅いという話もありますね。
局所化されているが飛び飛びの書き込みが必要になるので。
n6o
reviewed
Feb 8, 2026
| num_count = defaultdict(int) | ||
| for num in nums: | ||
| num_count[num] += 1 | ||
| return sorted(num_count, key=num_count.get, reverse=True)[:k] |
There was a problem hiding this comment.
(レビューではないのですがmm)
golang でも同じように書けないかなと思って調べたら最近できるようになっていたことを知りました。
勉強になりました。ありがとうございました。
slices package - slices - Go Packages
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.
この問題: Top K Frequent Elements - LeetCode
次の問題: Find K Pairs with Smallest Sums - LeetCode