LintCode - Rehashing

class Solution {
public: 
    vector rehashing(vector hashTable) {
        int n = hashTable.size(), m=n*2;
        vector res(m, NULL);
        for(int i=0;ival;
                ListNode* node = new ListNode(val);
                int index = val<0 ? (val%m+m)%m : val%m;
                ListNode* ccur = res[index];
                if(!ccur) res[index]=node;
                else{
                    while(ccur->next){
                        ccur = ccur->next;
                    }
                    ccur->next = node;
                }
                cur = cur->next;
            }
        }
        return res;
    }
};

 

你可能感兴趣的:(LintCode)