Skip to content

Commit 33afa9f

Browse files
committed
Time: 4 ms (49.93%), Space: 7.2 MB (22.04%) - LeetHub
1 parent 6676e5e commit 33afa9f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
ListNode* middleNode(ListNode* head) {
4+
ListNode* ptr1=head;
5+
int len=0;
6+
while(ptr1){
7+
len++;
8+
ptr1=ptr1->next;
9+
}
10+
ptr1=head;
11+
if(len & 1) len=len/2+1;
12+
else len=(len/2)+1;
13+
for(int i=1;i<len;i++){
14+
head=head->next;
15+
}
16+
return head;
17+
}
18+
};

0 commit comments

Comments
 (0)