MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / ListNode

Class ListNode

src/com/blankj/structure/ListNode.java:11–53  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/05/18 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class ListNode {
12
13 public int val;
14 public ListNode next;
15
16 public ListNode(int x) {
17 val = x;
18 }
19
20 /**
21 * 创建测试数据
22 *
23 * @param data [XX,XX,XX]
24 * @return {@link ListNode}
25 */
26 public static ListNode createTestData(String data) {
27 if (data.equals("[]")) return null;
28 data = data.substring(1, data.length() - 1);
29 String[] split = data.split(",");
30 int len = split.length;
31 ListNode[] listNode = new ListNode[len + 1];
32 listNode[0] = new ListNode(Integer.valueOf(split[0]));
33 for (int i = 1; i < len; i++) {
34 listNode[i] = new ListNode(Integer.valueOf(split[i]));
35 listNode[i - 1].next = listNode[i];
36 }
37 return listNode[0];
38 }
39
40 public static void print(ListNode listNode) {
41 if (listNode == null) {
42 System.out.println("null");
43 return;
44 }
45 StringBuilder str = new StringBuilder("[" + String.valueOf(listNode.val));
46 ListNode p = listNode.next;
47 while (p != null) {
48 str.append(",").append(String.valueOf(p.val));
49 p = p.next;
50 }
51 System.out.println(str.append("]"));
52 }
53}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected