[Java] Clean Backtracking, beats 100%
\nint res = -1, minDiff = Integer.MAX_VALUE;\n    \n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        Arrays.sort(baseCosts
```\nint res = -1, minDiff = Integer.MAX_VALUE;\n    \n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        Arrays.sort(baseCosts);\n        Arrays.sort(toppingCosts);\n        \n        for(int bCost : baseCosts){\n            int diff = Math.abs(bCost - target);\n            search(toppingCosts, 0, bCost, target);\n        }\n        return res;\n    }\n    \n    public void search(int[] nums, int index, int preSum, int target){\n        if(preSum > target && preSum - target > minDiff) return;\n        int diff = Math.abs(preSum - target);\n        if(diff == minDiff){\n            if(preSum < res) res = preSum;\n        }\n        if(diff < minDiff) {\n            minDiff = diff;\n            res = preSum;\n        }\n     \n        for(int i = index; i < nums.length; i++){\n            search(nums, i + 1, preSum + nums[i], target);\n            search(nums, i + 1, preSum + nums[i] * 2, target);\n        }\n        \n    }\n```
[]