Posted on:
Last modified:
一般使用 dummy head 的话,循环条件是 while p.next, 而不使用的话,则是 while p.
int reverseList(ListNode node) {
if (node == null || node.next == null) {
return node;
}
ListNode head = reverseList(node.next);
node.next.next = node;
node.next = null;
return head;
}
都比较简单,主要是细节的使用。
© 2016-2022 Yifei Kong. Powered by ynotes
All contents are under the CC-BY-NC-SA license, if not otherwise specified.
Opinions expressed here are solely my own and do not express the views or opinions of my employer.
友情链接: MySQL 教程站