```
public boolean canPartition(int[] nums) {
int sum = 0;
for (int num : nums) {
sum += num;
}
if (sum % 2 != 0) {
return false;
}
int target = sum / 2;
Arrays.sort(nums);
return helper(nums, nums.length - 2, target - nums[nums.length - 1]);
}
public boolean helper(int[] nums, int idx, int target) {
if (target == 0) {
return true;
} if (target < 0 || idx < 0) {
return false;
}
return helper(nums, idx - 1, target - nums[idx]) || helper(nums, idx - 1, target);
}
```