-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportion.java
120 lines (89 loc) · 3.23 KB
/
portion.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// import Parents.ListNode;
// class Solution {
// public ListNode reverseEvenLengthGroups(ListNode head) {
// //ans is going to be head of our resulting linkedlist
// // adding 1st group nodes to ans and removing them from given list
// // 1st group only contains head of given linkedlist
// ListNode ans=head;
// ListNode temp=head.next;
// head.next=null;
// head=temp;
// int size=Size(head); //size of given likedlist
// int k=2; //size of current group
// // this loop will create a linkedlist templist having all nodes of a group (of size k)
// while(temp!=null && k<=size){
// ListNode templist=null;
// int count=k;
// // adding all nodes of group to templist and removing respective nodes from given linkedlist
// while(count-->0){
// templist=addLast(templist,temp.val);
// temp=remFirst(temp);
// }
// // now check if size of group is even then
// if(k%2==0){
// templist=rev(templist); //reverse templist
// }
// ans= add(ans,templist); //merge ans and templist
// size-=k;
// k++;
// }
// size=Size(temp);
// if(size%2==0){
// temp=rev(temp);
// }
// ans=add(ans,temp);
// return ans;
// }
// // Function to determine size of the LinkedList
// public int Size(ListNode head){
// ListNode temp=head;
// int size=0;
// while(temp!=null){
// temp=temp.next;
// size++;
// }
// return size;
// }
// // this Function will add a node(having data val) at the last of linkedlist
// public ListNode addLast(ListNode head,int val){
// ListNode nn= new ListNode(val);
// if(head==null){
// return nn;
// }
// ListNode temp=head;
// while(temp.next!=null){
// temp=temp.next;
// }
// temp.next=nn;
// return head;
// }
// // this function will remove the first node of the linkedlist
// public ListNode remFirst(ListNode head){
// ListNode temp=head;
// head=head.next;
// temp.next=null;
// return head;
// }
// // This function will merge two linkedlist
// public ListNode add(ListNode list1,ListNode list2){
// ListNode temp=list1;
// while(temp.next!=null){
// temp=temp.next;
// }
// temp.next=list2;
// return list1;
// }
// // this Function will reverse the LinkedList
// public ListNode rev(ListNode head){
// ListNode prev=null;
// ListNode curr= head;
// while(curr!=null){
// ListNode currnext=curr.next;
// curr.next=prev;
// prev=curr;
// curr=currnext;
// }
// head=prev;
// return head;
// }
// }