Open
Conversation
t9a-dev
reviewed
Dec 13, 2025
Comment on lines
+14
to
+26
| stack<int> st; | ||
| while (head != nullptr) { | ||
| st.push(head->val); | ||
| head = head->next; | ||
| } | ||
| ListNode* dummy = new ListNode(0); | ||
| ListNode* curr = dummy; | ||
| while (!st.empty()) { | ||
| int num = st.top(); st.pop(); | ||
| curr->next = new ListNode(num); | ||
| curr = curr->next; | ||
| } | ||
| return dummy->next; |
There was a problem hiding this comment.
変数名(st,curr)について、個人的には省略する理由がなければ、省略せずにそのままstack,currentにすると思いました。未来の自分を含めた他の人が読む時に、頭の中で元の単語に戻すという作業をさせない方が楽だなという気持ちです。
以下、nodchipさんのコメントを引用します。
英単語から文字を削って識別子とした場合、読み手に取って認知負荷が上がる場合があります。原則フルスペルで書くことをおすすめします。情報科学やソフトウェアエンジニアリングにおいて有名な略語 (API, LAN, DNS, JSON 等) や、所属するチーム内で頻繁に使われている略語は、使用しても問題ないと思います。また、 number of を表す num_ sum of を表す sum_ maximum number of を表す max_ minimum number of を表す min_ などは、しばしば見かけますので、使ってもよいと思います。 参考までにスタイルガイドへのリンクを貼ります。 https://google.github.io/styleguide/pyguide.html#316-naming Avoid abbreviation. In particular, do not use abbreviations that are ambiguous or unfamiliar to readers outside your project, and do not abbreviate by deleting letters within a word. 上記のスタイルガイドは唯一絶対のルールではなく、複数あるスタイルガイドの一つに過ぎないということを念頭に置くことをお勧めします。また、所属するチームにより何が良いとされているかは変わります。自分の中で良い書き方の基準を持ちつつ、チームの平均的な書き方で書くことをお勧めいたします。
t9a-dev
reviewed
Dec 13, 2025
| ListNode* dummy = new ListNode(0); | ||
| ListNode* curr = dummy; | ||
| while (!st.empty()) { | ||
| int num = st.top(); st.pop(); |
There was a problem hiding this comment.
C++言語の慣習、文化的なものから来るコードスタイルではない場合、ここは2行に分けて書くのが一般的かなと思いました。
Suggested change
| int num = st.top(); st.pop(); | |
| int num = st.top(); | |
| st.pop(); |
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/reverse-linked-list/description/
次に解く問題:https://leetcode.com/problems/kth-largest-element-in-a-stream/description/