206. Reverse Linked List


206. Reverse Linked List

     public ListNode reverseList(ListNode head) {
        ListNode pre=null;
        ListNode cur=head;
        while(cur!=null){
            ListNode next=cur.next;
            cur.next=pre;
            pre=cur;
            cur=next;
        }
        return pre;
    }
public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode newHead = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return newHead;
    }

作者:LeetCode-Solution
链接:https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/solution/fan-zhuan-lian-biao-by-leetcode-solution-jvs5/

文章作者:   future
版权声明:   本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 future !
 上一篇
25. Reverse Nodes in k-Group 25. Reverse Nodes in k-Group
25. Reverse Nodes in k-Groupk 个一组反转链表 public ListNode reverseKGroup(ListNode head, int k) { ListNode ha
2021-02-25 future
下一篇 
322. 零钱兑换 322. 零钱兑换
322. 零钱兑换动态规划 public int coinChange(int[] coins, int amount) { // 自底向上的动态规划 if(coins.length
2021-02-25 future
  目录