知识点不足记录


今天在刷算法题时,对于反转链表,还是不能够理解

 public static class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
        this.val = val;
    }
}
    public class Solution {
        public ListNode ReverseList(ListNode head) {
            if(head == null){
                return null;
            }
            ListNode newHead = null;
            ListNode next = null;
            while(head != null){
                next = head.next;        //保存断裂后原始链表的头节点
                head.next = newHead;     //改变指针指向方向,将当前节点指向反转链表的头节点
                newHead = head;          // newHead 指向反转链表的新的头节点
                head = next;             //继续循环
            }
            return newHead;
        }
    }
}

不能理解的地方如下,参考资料: https://blog.csdn.net/coder_kirito/article/details/99659392

                 head.next = newHead;     //改变指针指向方向,将当前节点指向反转链表的头节点
                newHead = head;          // newHead 指向反转链表的新的头节点
                head = next;             //继续循环

Author: Doctor-Deng
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Doctor-Deng !
 Previous
Mysql-java-shujuleixing Mysql-java-shujuleixing
MYSQL类型与实体类中属性的JAVA类型对应表 document.querySelectorAll('.github-emoji') .forEach(el => { if (
2020-03-10 Doctor-Deng
Next 
博客问题记录 博客问题记录
YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 4, column 1:ERROR
2020-03-09 Doctor-Deng
  TOC