-
Notifications
You must be signed in to change notification settings - Fork 0
Update AddTwoNumbers.md #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: memo.md
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,25 +21,26 @@ | |
|
|
||
| ```cpp | ||
| class Solution { | ||
| ListNode* addTwoNumber(ListNode* l1, ListNode* l2) { | ||
| public: | ||
| ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { | ||
| ListNode dummy_head = ListNode(); | ||
| ListNode* result_tail = &dummy_head; | ||
| int carryover = 0; | ||
| while (l1 || l2 || carryover) { | ||
| int value = carryover; | ||
| int digitSum = carryover; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. snake_case と lowerCamel が混ざっているのが気になりました。 参考までにスタイルガイドへのリンクを貼ります。 https://google.github.io/styleguide/cppguide.html#Variable_Names
上記のスタイルガイドは唯一絶対のルールではなく、複数あるスタイルガイドの一つに過ぎないということを念頭に置くことをお勧めします。また、所属するチームにより何が良いとされているかは変わります。自分の中で良い書き方の基準を持ちつつ、チームの平均的な書き方で書くことをお勧めいたします。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメントありがとうございます。 |
||
| if (l1) { | ||
| value += l1->val; | ||
| digitSum += l1->val; | ||
| l1 = l1->next; | ||
| } | ||
| if (l2) { | ||
| value += l2->val; | ||
| digitSum += l2->val; | ||
| l2 = l2->next; | ||
| } | ||
|
|
||
| carryover = value / 10; | ||
| value %= 10; | ||
| carryover = digitSum / 10; | ||
| digitSum %= 10; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この段階でdigitSumは意味的にはdigitSumではなくなってしまうので、別の変数に入れるか、この後直接 |
||
|
|
||
| result_tail->next = new ListNode(value); | ||
| result_tail->next = new ListNode(digitSum); | ||
| result_tail = result_tail->next; | ||
| } | ||
| return dummy_head.next; | ||
|
|
@@ -48,5 +49,24 @@ class Solution { | |
|
|
||
| ``` | ||
|
|
||
| ##Step2 8/1 10:50 | ||
| ##Step2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. マークダウンとして装飾するには##の後に半角空白を入れて
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメントありがとうございます。 |
||
|
|
||
| * Jikuharaさん https://github.com/Jikuhara/LeetCode/pull/11/commits/846d5c426f15565ccb1106430681b1f388b24538 | ||
| -> skypenguins on Jun 14 さんのコメント 処理の始めから value に次々に l1 , l2 の値を足していく処理のようですが、変数の生存期間が長くてなんとなく頭の一時記憶を占める感覚があります。 | ||
|
|
||
| * new で確保したメモリは、LeetCodeでは解放の必要はないが、実務ではNG. | ||
| LeetCode テスト環境では、実行終了後プロセスごと破棄。OSが確保していたヒープを一括で回収する仕様になっている。 | ||
| https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers | ||
|
|
||
| * コード領域、データ領域、スタック領域、ヒープ領域に関して | ||
| https://discord.com/channels/1084280443945353267/1237649827240742942/1251960606077091981 | ||
|
|
||
| ##Step3 | ||
|
|
||
| step3は、それほど時間は掛からなかった。 | ||
| 丁度LeetCodeを初めて1週間ほど。やはり基礎的な知識が欠落してるので、理解に時間がかかりすぎている。 | ||
| あと8-9カテゴリで https://www.learn-cpp.org/en/Welcome を一通り終える。 | ||
| LeetCodeの一歩手前みたいな、書く練習と読む練習ができるものを探すか、このままLeetCodeを続けるか考えたい。 | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
carry で、コンピューター用語で繰り上げを表します。こちらのほうがシンプルだと思います。 carryover でも十分伝わると思いますので、好みの問題だと思います。