分享至
鏈表的基本形式是:1 -> 2 -> 3 -> null,如果要反轉為 1 -> 3 -> 2 -> null。那要如何修改下面的程式呢?public ListNode reverse(ListNode head) {ListNode prev = null;while (head != null) {ListNode next = head.next;head.next = prev;prev = head;head = next;}return prev;}
已邀請的邦友 {{ invite_list.length }}/5
IT邦幫忙