力扣算法学习(四)

2022/1/5 20:04:10

本文主要是介绍力扣算法学习(四),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

链表的中间结点

 public ListNode middleNode(ListNode head) {
        ListNode fast=head,slow=head;//新建双节点一快一慢
        while(fast!=null&&fast.next!=null){
            slow=slow.next;
            fast=fast.next.next;//当fast比slow双倍移动时
        }
        return slow;
    }


这篇关于力扣算法学习(四)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程