当前位置:
首页 >
Solution 24: 链表翻转
发布时间:2023/11/27
41
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Solution 24: 链表翻转
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
程序
public class ListReverse {public ListNode reverseList(ListNode head) {if (head == null) {return head;}ListNode pre = head;ListNode cur = pre.next;pre.next = null;while (cur != null) {ListNode next = cur.next;cur.next = pre;pre = cur;cur = next;}return pre;}public ListNode reverseList2(ListNode head) {ListNode pre = null;ListNode cur = head;while (cur!=null) {ListNode next = cur.next;cur.next = pre;pre = cur;cur = next;}return pre;}
}
第一种是比较常见,第二种更为简洁。
转载于:https://www.cnblogs.com/harrygogo/p/4629483.html
总结
以上是生活随笔为你收集整理的Solution 24: 链表翻转的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 树知春不久归下一句是什么呢?
- 下一篇: UICollectionView的使用方