(Power button) 206. Reverse list

topic

Here Insert Picture Description

Problem-solving results

Here Insert Picture Description

Problem-solving ideas: the first interpolation method

Create an empty list, the first interpolation by inserting

Problem-solving Code

class Solution {
      public ListNode reverseList(ListNode head) {
          ListNode pre = null;
          ListNode cur = head;
          while(cur != null){
//             tempnode.next = head;
//             tempnode = head; //尾插法
              ListNode nextTemp = cur.next;
              cur.next = pre;
              pre = cur;//头插法
              cur = nextTemp;
          }
          return pre;
    }
}
Published 109 original articles · won praise 128 · views 40000 +

Guess you like

Origin blog.csdn.net/JAck_chen0309/article/details/104443785