LinkedList:反转链表

    public static Node reverseList(Node node) {
        Node last = null;
        Node next = null;
        while (node != null) {
            next = node.next;
            node.next = last;
            last = node;
            node = next;
        }
        
        return last;
    }

你可能感兴趣的:(LinkedList:反转链表)