-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertLinkedList.java
More file actions
60 lines (34 loc) · 1.08 KB
/
Copy pathInsertLinkedList.java
File metadata and controls
60 lines (34 loc) · 1.08 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class InsertLinkedList{
public static class ListNode{
int val;
ListNode next;
ListNode(int x){
val = x;
}
}
public static ListNode check(ListNode head){
ListNode start = head;
while(start!=null){
if(start.val%2==0){
ListNode ad = new ListNode(1);
ad.next = start.next;
start.next = ad;
}
start = start.next;
}
return head;
}
public static void main(String []args){
ListNode head = new ListNode(0);
ListNode q = head;
for(int i=1;i<8;i++){
q.next = new ListNode(i);
q = q.next;
}
ListNode ans = check(head.next);
while(ans!=null){
System.out.println(ans.val);
ans = ans.next;
}
}
}