Open
Conversation
oda
reviewed
May 30, 2024
| ```python | ||
| from dataclasses import dataclass | ||
|
|
||
| @dataclass |
thonda28
reviewed
May 31, 2024
| ```python | ||
| class Solution: | ||
| def topKFrequent(self, nums: List[int], k: int) -> List[int]: | ||
| tally = Counter(nums) |
There was a problem hiding this comment.
(本質的な話ではないのですが)tally という単語を見たことがなかったので、少し戸惑いました。これは僕個人の英語力の問題かもしれないので、他の人はどうなのか気になります。
Owner
Author
There was a problem hiding this comment.
Rubyのメソッドに Enumerable#tally というのがあって、それで自分は知って使っちゃいました。メソッド名として使われているこの語が変数名として使っても自然なのかは分からないです...
- Rubyのtallyの議論: https://bugs.ruby-lang.org/issues/11076#note-10
- Githubで検索: https://github.com/search?q=%22+tally+%22&type=code&p=1
↑この辺見てみましたが、うーん何とも言えない感じでした
There was a problem hiding this comment.
Rubyのメソッドに Enumerable#tally というのがあって、それで自分は知って使っちゃいました。
リンクの共有ありがとうございます。Ruby を触ったことがなく知らなかったので勉強になりました。このメソッドの処理を見ると、今回の用途に合っていそうなので問題なさそうです。
コメントしたからにはなにか良い代案を出そうと思いましたが、パッと出なかったです。(僕が過去に解いたものを見返しましたが freq_dict だとか freq と書いていてあんまりイケてなさそうでした。)
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/top-k-frequent-elements/description/