Leetcode206-链表中箭头转移和内容转移

链表中箭头转移和内容转移

  • 链表中特别注意xxx.next=xxx 和xxx=xxx的区别
  • xxx.next=xxx表示将指针(箭头)转移 xxx=xxx表示将内容转移

Leetcode206翻转链表

  • 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表
    public ListNode reverseList(ListNode head) {
        ListNode pre=null;
        ListNode cur=head;
        ListNode temp=null;

        while(cur!=null){
            temp=cur.next;
            cur.next=pre;
            pre=cur;
            cur=temp;
        }

        return pre;
    }
posted @ 2022-03-31 21:08  fao99  阅读(51)  评论(0)    收藏  举报