# 恢复博客更新 --- 逆序单项链表 要求空间复杂度o(1) 时间复杂度o(n)

1. 复习微积分

2. 复习概率论和统计学

3. 刷一遍leetcode

``` 1 package com.autonavi.algo;
2
3 public class ReverseLinkedList {
4
5     public static void main(String[] args){
6         Node node0 = new Node(null,0);
7         Node node1 = new Node(null,1);
8         Node node2 = new Node(null,2);
9
10         node0.next = node1;
11         node1.next = node2;
12
13         Node node = node0;
14         while(null != node){
15             System.out.println(node.value);
16             node = node.next;
17         }
18
19         Node newHead = reverse(node0);
20
21         node = newHead;
22         while(null != node){
23             System.out.println(node.value);
24             node = node.next;
25         }
26     }
27
28     public static Node reverse(Node head){
29         Node p;
30         Node tmp = head.next;
31         head.next = null;
32         while(tmp != null){
33             p = tmp;
34             tmp = tmp.next;
35             p.next = head;
36             head = p;
37         }
39     }
40 }
41
42 class Node{
43     Node next;
44     int value;
45     Node(Node next, int value){
46         this.next = next;
47         this.value = value;
48     }
49     @Override
50     public String toString() {
51         return "Node [next=" + next + ", value=" + value + "]";
52     }
53
54 }```

原文作者：蟹粉小笼包
原文地址: https://www.cnblogs.com/aalex/p/5231492.html
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。