0.4
This commit is contained in:
1 parent
55faca1edf
commit
97f3b8d69e
3 files changed
+48
-25
No files matched your search
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m -Xlog:disable"
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.hong.www;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class A212 {
|
||||||
|
public List<String> findWords(char[][] board, String[] words) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
-25
@@ -1,48 +1,58 @@
|
|||||||
package com.hong.www;
|
package com.hong.www;
|
||||||
|
|
||||||
public class A25 {
|
public class A25 {
|
||||||
|
public ListNode reverseList(ListNode root){
|
||||||
|
ListNode temp=null;
|
||||||
|
ListNode next=root.next;
|
||||||
|
while(root!=null){
|
||||||
|
next=root.next;
|
||||||
|
root.next=temp;
|
||||||
|
temp=root;
|
||||||
|
root=next;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
public ListNode reverseKGroup(ListNode head, int k) {
|
public ListNode reverseKGroup(ListNode head, int k) {
|
||||||
|
if(k==1||head==null){
|
||||||
|
return head;
|
||||||
|
}
|
||||||
ListNode dummy = new ListNode(0, head);
|
ListNode dummy = new ListNode(0, head);
|
||||||
ListNode prev = dummy;
|
ListNode prev = dummy;
|
||||||
ListNode next;
|
ListNode next;
|
||||||
ListNode curr = head;
|
ListNode curr = head;
|
||||||
int time = 1;
|
ListNode from =head;
|
||||||
|
ListNode from1;
|
||||||
|
int is=0;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (time < k) {
|
for(int i = 0; i < k-1 && curr != null; i++) {
|
||||||
time++;
|
|
||||||
curr = curr.next;
|
curr = curr.next;
|
||||||
if (curr == null) {
|
if(curr==null){
|
||||||
return prev.next;
|
is=1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next = curr.next;
|
if(is==1){
|
||||||
curr.next = null;
|
prev.next=from;
|
||||||
ListNode temp = prev.next;
|
break;
|
||||||
ListNode last;
|
}else if(curr!=null){
|
||||||
ListNode nexttemp = temp.next;
|
next=curr.next;
|
||||||
while (nexttemp != null) {
|
curr.next=null;
|
||||||
nexttemp = nexttemp.next;
|
prev.next=reverseList(from);
|
||||||
last = temp;
|
prev=from;
|
||||||
temp = temp.next;
|
from=next;
|
||||||
temp.next = last;
|
curr=from;
|
||||||
last = temp;
|
}else{
|
||||||
|
prev.next=from;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
prev.next.next = null;
|
|
||||||
prev.next=temp;
|
|
||||||
prev=temp;
|
|
||||||
curr=next;
|
|
||||||
time=1;
|
|
||||||
}
|
}
|
||||||
//return dummy;
|
return dummy.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
A25 a25 = new A25();
|
A25 a25 = new A25();
|
||||||
ListNode head = new ListNode(1);
|
ListNode head = new ListNode(1);
|
||||||
head.next = new ListNode(2);
|
head.next = new ListNode(2);
|
||||||
head.next.next = new ListNode(3);
|
|
||||||
head.next.next.next = new ListNode(4);
|
|
||||||
head.next.next.next.next = new ListNode(5);
|
|
||||||
int k = 2;
|
int k = 2;
|
||||||
ListNode result = a25.reverseKGroup(head, k);
|
ListNode result = a25.reverseKGroup(head, k);
|
||||||
while (result != null) {
|
while (result != null) {
|
||||||
|
|||||||
Reference in new issue
Block a user