File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -115,13 +115,17 @@ public synchronized ListNode removeFromEnd() {
115
115
ListNode p = head , q = null , next = head .getNext ();
116
116
if (next == null ) {
117
117
head = null ;
118
+ // reduce the length of the list
119
+ length -=1 ;
118
120
return p ;
119
121
}
120
122
while ((next = p .getNext ()) != null ) {
121
123
q = p ;
122
124
p = next ;
123
125
}
124
126
q .setNext (null );
127
+ // reduce the length of the list
128
+ length -=1 ;
125
129
return p ;
126
130
}
127
131
@@ -132,12 +136,16 @@ public synchronized void removeMatched(ListNode node) {
132
136
return ;
133
137
if (node .equals (head )) {
134
138
head = head .getNext ();
139
+ // reduce the length of the list
140
+ length -=1 ;
135
141
return ;
136
142
}
137
143
ListNode p = head , q = null ;
138
144
while ((q = p .getNext ()) != null ) {
139
145
if (node .equals (q )) {
140
146
p .setNext (q .getNext ());
147
+ // reduce the length of the list
148
+ length -=1 ;
141
149
return ;
142
150
}
143
151
p = q ;
You can’t perform that action at this time.
0 commit comments