public static void main(String[] args) {
Node node = new Node(1,new Node(2,new Node(3,new Node(4,new Node(1,new Node(2,null))))));
Node mid = process(node);
System.out.println(mid.getValue());
}
private static Node process(Node node) {
if (null==node || node.getNext()==null) {
return node;
}
Node quick = node.getNext();
Node slow = node.getNext();
while (quick.getNext()!=null
&& quick.getNext().getNext()!=null){
quick=quick.getNext().getNext();
slow=slow.getNext();
}
return slow;
}
链表中点问题
最新推荐文章于 2024-08-27 19:04:13 发布