forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListNode.java
More file actions
36 lines (31 loc) · 741 Bytes
/
ListNode.java
File metadata and controls
36 lines (31 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package normal;
/**
* @program JavaBooks
* @description: 链表
* @author: mf
* @create: 2019/10/17 01:03
*/
public class ListNode {
int val;
ListNode next;
public ListNode(int val) {
this.val = val;
}
public static ListNode setListNode(int[] arr) {
ListNode node = new ListNode(-1);
ListNode p1 = node;
for (int num : arr) {
ListNode temp = new ListNode(num);
p1.next = temp;
p1 = p1.next;
}
return node.next;
}
public static void printNode(ListNode node) {
while (node != null) {
System.out.print(node.val + "->");
node = node.next;
}
System.out.print("null");
}
}