题目
截图自官方
代码
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
// 简单题,没啥说的
public ListNode middleNode(ListNode head) {
int n=0;
ListNode temp=head;
while(temp!=null){
n++;
temp=temp.next;
}
for(int i=0;i<n/2;i++){
head=head.next;
}
return head;
}
}