写个链表反转的算法

没出去面试被打击之前,你永远不知道自己有多low逼,其实也不是技术不如别人,就是面试的技巧吧,去大公司面试,一般聊两句之后觉得还可以的就会问你算法。关于算法,其实平时的工作中不太用得着,但是却能考验一个人的能力,下面就先写一个链表反转的算法吧

    public ListNode reverseList(ListNode head) {
        ListNode first = null;
        ListNode current = head;
        ListNode next = null;
        while(current!=null){
            next = current.next;
            current.next= first;
            first = current;
            current = next;
        }
        return first;
    }
    

猜你喜欢

转载自www.cnblogs.com/xiao-tangyuan/p/9563899.html