Skip to content

2. Add Two Numbers#6

Open
hemispherium wants to merge 1 commit intomainfrom
0002-add-two-numbers
Open

2. Add Two Numbers#6
hemispherium wants to merge 1 commit intomainfrom
0002-add-two-numbers

Conversation

@hemispherium
Copy link
Owner

@hemispherium hemispherium self-assigned this Dec 11, 2025
Copy link

@fv17 fv17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再帰を使って解く方法も議論されているので、そちらも是非

sum += l2->val;
l2 = l2->next;
}
curr->next = new ListNode(sum % 10);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curr という名前から現在操作中の桁(ノード)を表すものだなと判断する読み手が多い気がします。
しかし、書いていただいたコードでは操作中の桁を curr そのものではなく next に代入していることが少し気になりました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかにdummyをListNode(0)で作って、最終的にdummy->nextを返している都合上curr->nextに操作した桁を代入していますが、prevみたいな名前にするのも変な気がして難しいですね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants