Menu Sidebar
Menu

linked list

Quicksort for LinkList

当年微软面试题: 少了两个= null, 结果木offer public static ListNode sort(ListNode head){ if (head == null) return head; ListNode pivot = new ListNode(head.val); head = head.next; // remove pivot ListNode lessDummy = new ListNode(0); ListNode moreDummy = new ListNode(0); ListNode lessP = lessDummy; ListNode moreP = moreDummy; ListNode p = head; while (p != null){ if (p.val < […]

[LintCode] Linked List Cycle

public boolean hasCycle(ListNode head) { // write your code here if(head == null) return false; ListNode fast = head; ListNode slow = head; while(fast.next != null && fast.next.next != null) { slow = slow.next; fast = fast.next.next; if(slow == fast) return true; } return false; }

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930