File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ 他の回答者のコードやレビューを読んで修正
3
+ whileを入れ子にするとにた処理をまとめれる
4
+ */
5
+ class Solution {
6
+ public:
7
+ ListNode* deleteDuplicates (ListNode* head) {
8
+ ListNode* current = head;
9
+
10
+ while (current) {
11
+ while (current && current->next && current->val == current->next ->val ) {
12
+ current->next = current->next ->next ;
13
+ }
14
+ current = current->next ;
15
+ }
16
+ return head;
17
+ }
18
+ };
Original file line number Diff line number Diff line change
1
+ /*
2
+ 2つ目のwhileに不要な記述があったので削除
3
+ リストを先頭から見ていき、currentとその次の要素が同地な場合は削除ループを回す
4
+ 削除が完了したらcurrentを進める
5
+ 最後にheadを返して完了
6
+ */
7
+ class Solution {
8
+ public:
9
+ ListNode* deleteDuplicates (ListNode* head) {
10
+ ListNode* current = head;
11
+ while (current) {
12
+ while (current->next && current->val == current->next ->val ) {
13
+ current->next = current->next ->next ;
14
+ }
15
+ current = current->next ;
16
+ }
17
+ return head;
18
+ }
19
+ };
You can’t perform that action at this time.
0 commit comments