随笔分类 -  Linked List

摘要:class Solution { public ListNode sortList(ListNode head) { if(head==null||head.next==null) return head; ListNode p=head,q=head; while(p.next!=null&&p.next.next... 阅读全文
posted @ 2017-10-17 04:58 Weiyu Wang 阅读(98) 评论(0) 推荐(0)
摘要:class Solution { public ListNode insertionSortList(ListNode head) { ListNode pre=new ListNode(0); ListNode p=head, q; while(p!=null) { q=pre; ... 阅读全文
posted @ 2017-10-17 04:41 Weiyu Wang 阅读(119) 评论(0) 推荐(0)
摘要:class Solution { public void reorderList(ListNode head) { ListNode p=head, q=head; while(p!=null&&p.next!=null) { p=p.next.next; q=q.next; ... 阅读全文
posted @ 2017-10-12 05:58 Weiyu Wang 阅读(124) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode detectCycle(ListNode head) { ListNode p=head,q=head; while(p!=null&&p.next!=null) { p=p.next.next; q=q.next... 阅读全文
posted @ 2017-10-10 12:30 Weiyu Wang 阅读(121) 评论(0) 推荐(0)
摘要:public class Solution { public RandomListNode copyRandomList(RandomListNode head) { Map map=new HashMap(); RandomListNode p=new RandomListNode(0); p.next=head; Ran... 阅读全文
posted @ 2017-10-10 02:45 Weiyu Wang 阅读(119) 评论(0) 推荐(0)
摘要:class Solution { public ListNode reverseBetween(ListNode head, int m, int n) { ListNode pre=new ListNode(0); pre.next=head; ListNode p=pre; for(int i=0;i0) ... 阅读全文
posted @ 2017-09-28 13:23 Weiyu Wang 阅读(102) 评论(0) 推荐(0)
摘要:class Solution { public ListNode partition(ListNode head, int x) { ListNode l1=new ListNode(0); ListNode l2=new ListNode(0); ListNode pre=new ListNode(0); pre.next... 阅读全文
posted @ 2017-09-28 06:32 Weiyu Wang 阅读(103) 评论(0) 推荐(0)
摘要:class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode pre=new ListNode(0); pre.next=head; ListNode p=pre; while(p!=null&&p.next!=null) ... 阅读全文
posted @ 2017-09-27 11:20 Weiyu Wang 阅读(104) 评论(0) 推荐(0)
摘要:class Solution { public ListNode rotateRight(ListNode head, int k) { ListNode preNode=new ListNode(0); preNode.next=head; ListNode p=preNode; int len=0; wh... 阅读全文
posted @ 2017-09-26 04:37 Weiyu Wang 阅读(114) 评论(0) 推荐(0)
摘要:class Solution { public ListNode reverseKGroup(ListNode head, int k) { if(head==null||k==1) return head; ListNode preNode=new ListNode(0); preNode.next=head; ... 阅读全文
posted @ 2017-09-23 05:07 Weiyu Wang 阅读(111) 评论(0) 推荐(0)
摘要:Iteration 阅读全文
posted @ 2017-09-23 02:07 Weiyu Wang 阅读(93) 评论(0) 推荐(0)
摘要:class Solution { public ListNode mergeKLists(ListNode[] lists) { PriorityQueue que=new PriorityQueue((a,b)->a.val-b.val); for(ListNode list:lists) if(list!=null) ... 阅读全文
posted @ 2017-09-23 01:51 Weiyu Wang 阅读(109) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode pre=new ListNode(0); pre.next=head; ListNode p=pre,q=pre; for(int i=0;i<n... 阅读全文
posted @ 2017-09-23 01:30 Weiyu Wang 阅读(118) 评论(0) 推荐(0)