File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ レビュー指摘を受けて修正したコード
3
+ 3重のwhileはそれで解けなくはないしパスするものの読みづらい
4
+ ifの代わりにwhileを使うと連続した同値グループをそのブロック内で処理できる利点があるが流石に3重whileは読みづらいのでダメ
5
+ ifを使用して、外側のループの中で処理する。
6
+ */
7
+ class Solution {
8
+ public:
9
+ ListNode* deleteDuplicates (ListNode* head) {
10
+ ListNode dummy_node = ListNode (-1 , head);
11
+ ListNode* inspecting_node = &dummy_node;
12
+ while (inspecting_node) {
13
+ ListNode* group_top = inspecting_node->next ;
14
+ if (group_top && group_top->next && group_top->val == group_top->next ->val ) {
15
+ int group_val = group_top->val ;
16
+ while (group_top && group_top->val == group_val) {
17
+ inspecting_node->next = group_top->next ;
18
+ group_top = group_top->next ;
19
+ }
20
+ } else {
21
+ inspecting_node = inspecting_node->next ;
22
+ }
23
+ }
24
+ return dummy_node.next ;
25
+ }
26
+ };
You can’t perform that action at this time.
0 commit comments