diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9250139 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m -Xlog:disable" +} \ No newline at end of file diff --git a/src/com/hong/www/A212.java b/src/com/hong/www/A212.java new file mode 100644 index 0000000..0d92a13 --- /dev/null +++ b/src/com/hong/www/A212.java @@ -0,0 +1,10 @@ +package com.hong.www; + +import java.util.*; + +public class A212 { + public List findWords(char[][] board, String[] words) { + List result = new ArrayList<>(); + return result; + } +} diff --git a/src/com/hong/www/A25.java b/src/com/hong/www/A25.java index 229a8d6..28fc3d2 100644 --- a/src/com/hong/www/A25.java +++ b/src/com/hong/www/A25.java @@ -1,48 +1,58 @@ package com.hong.www; 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) { + if(k==1||head==null){ + return head; + } ListNode dummy = new ListNode(0, head); ListNode prev = dummy; ListNode next; ListNode curr = head; - int time = 1; + ListNode from =head; + ListNode from1; + int is=0; while (true) { - while (time < k) { - time++; + for(int i = 0; i < k-1 && curr != null; i++) { curr = curr.next; - if (curr == null) { - return prev.next; + if(curr==null){ + is=1; + break; } } - next = curr.next; - curr.next = null; - ListNode temp = prev.next; - ListNode last; - ListNode nexttemp = temp.next; - while (nexttemp != null) { - nexttemp = nexttemp.next; - last = temp; - temp = temp.next; - temp.next = last; - last = temp; + if(is==1){ + prev.next=from; + break; + }else if(curr!=null){ + next=curr.next; + curr.next=null; + prev.next=reverseList(from); + prev=from; + from=next; + curr=from; + }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) { A25 a25 = new A25(); ListNode head = new ListNode(1); 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; ListNode result = a25.reverseKGroup(head, k); while (result != null) {