public List<List<Integer>> fourSum(int[] num, int target) {
        List<List<Integer>> list = new ArrayList<List<Integer>>();
        
        int length = num.length;
        if (length < 4)
            return list;
            
        Arrays.sort(num);
        
        int lastA = Integer.MIN_VALUE;
        int lastB = Integer.MIN_VALUE;
        int lastC = Integer.MIN_VALUE;

        for (int i = 0; i < length -3; i ++) {
            if (lastA == num[i])
                continue;
                
            lastA = num[i];
            lastB = Integer.MIN_VALUE;
            
            for (int j = i + 1; j < length - 2; j ++) {
                if (lastB == num[j])
                    continue;
                
                lastB = num[j];
                
                int k = j + 1;
                int l = length - 1;
                int tmpTarget = target - num[i] - num[j];
                lastC = Integer.MIN_VALUE;
                
                while (l > k) {
                    if (num[k] == lastC) {
                        k ++;
                        continue;
                    }
                        
                    if (num[k] + num[l] < tmpTarget)
                        k ++;
                    else if (num[k] + num[l] > tmpTarget)
                        l --;
                    else {
                        ArrayList<Integer> tmpList = new ArrayList<Integer>();
                        tmpList.add(num[i]);
                        tmpList.add(num[j]);
                        tmpList.add(num[k]);
                        tmpList.add(num[l]);
                        list.add(tmpList);
                        lastC = num[k];
                        k ++;
                        l --;
                    }
                }
                
            }
            
            
        }
        
        return list;
    }