Conversation
| 空間計算量: O(1) | ||
|
|
||
| - head からノードを一つずつ走査。現在の対象ノードの値が次のノードと同一であればリンクをさらにその次につなぎなおす。そうでない場合に対象ノードを次に移動 | ||
| - 主役のノードは一人しかいないので、シンプルに node と命名した |
plushn
reviewed
Apr 11, 2025
|
|
||
| return head; | ||
| } | ||
| } |
oda
reviewed
Apr 12, 2025
| 他の方が描いたコードを見て、参考にしてコードを書き直してみる。 | ||
| 参考にしたコードのリンクは貼っておく。 | ||
| 読みやすいことを意識する。 | ||
| 他の解法も考えみる。 |
Owner
Author
There was a problem hiding this comment.
ありがとうございます。二重ループは非効率的だと思い込みがあり直感的に避けていましが、実際には変わらないのですね。
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode node = head;
while (node != null) {
while (node.next != null && node.val == node.next.val) {
node.next = node.next.next;
}
node = node.next;
}
return head;
}
}
Satorien
reviewed
Apr 16, 2025
| 他の解法も考えみる。 | ||
|
|
||
| - continue で 処理をスキップする方法。現在ノードを次に進める処理が else の中にある事に違和感があったのでこちらの方が見やすい | ||
| - https://github.com/shintaro1993/arai60/pull/6/files |
There was a problem hiding this comment.
仰る通り、elseだと並列の関係にある処理のように読めてしまうのでこっちの方が良いですね
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/remove-duplicates-from-sorted-list/
言語
Java
次に解く問題
Remove Duplicates from Sorted List II