标签:code 图片 int == head http info 指针 linked
题解:双指针
快指针一次两步,慢指针一次一步,当快指针走到结尾时候慢指针刚好到终点
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode middleNode(ListNode head) {
ListNode l=head,r=head;
while(true){
if(r==null||r.next==null) return l;
l=l.next;
r= r.next==null? null:r.next.next;
}
}
}
标签:code 图片 int == head http info 指针 linked
原文地址:https://www.cnblogs.com/cstdio1/p/13334622.html