@@ -0,0 +1,1509 @@
+package org.speedfirst.leetcode.not_in_oj.hashmap;%0A%0Aimport org.speedfirst.leetcode.basic.ListNode;%0A%0A/**%0A * Created by jiankuan on 1/21/15.%0A */%0Apublic class Rehashing %7B%0A%0A    /**%0A     * @param hashTable: A list of The first node of linked list%0A     * @return: A list of The first node of linked list which have twice size%0A     */%0A    public ListNode%5B%5D rehashing(ListNode%5B%5D hashTable) %7B%0A        int n = hashTable.length;%0A        int m = 2 * n;%0A        ListNode%5B%5D newHashTable = new ListNode%5Bm%5D;%0A%0A        for (ListNode head: hashTable) %7B%0A            ListNode cur = head;%0A            ListNode next = null;%0A            while (cur != null) %7B%0A                next = cur.next;%0A                int newPos = mod(cur.val, m);%0A                if (newHashTable%5BnewPos%5D == null) %7B%0A                    newHashTable%5BnewPos%5D = cur;%0A                    cur.next = null;%0A                %7D else %7B%0A                    ListNode newCur = newHashTable%5BnewPos%5D;%0A                    // find tail, talk with your interviewer to confirm whether it's necessary to append to the tail%0A                    while (newCur.next != null) %7B%0A                        newCur = newCur.next;%0A                    %7D%0A                    newCur.next = cur;%0A                    cur.next = null;%0A                %7D%0A                cur = next;%0A            %7D%0A        %7D%0A%0A        return newHashTable;%0A    %7D%0A%0A    private int mod(int a, int b) %7B%0A        if (a %3E= 0) %7B%0A            return a %25 b;%0A        %7D else %7B%0A            return (a %25 b + b) %25 b;%0A        %7D%0A    %7D%0A%7D%0A

add rehashing