Created
October 16, 2014 03:50
-
-
Save daskinne/a988690a839877c58ab6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean split53(int[] nums) { | |
return split_fn(0, nums, 0, 0, false, false); | |
} | |
public boolean split_fn(int start, int[] nums, int left, int right, boolean fiveLeft, boolean chosen) { | |
if (start >= nums.length) { | |
if (left == right) return true; | |
return false; | |
} | |
if (nums[start] % 5 == 0) { | |
if (!chosen) { | |
return split_fn(start + 1, nums, left + nums[start], right, true, true) || split_fn(start + 1, nums, left, right + nums[start], false, true); | |
} else { | |
return split_fn(start + 1, nums, left + ((fiveLeft) ? nums[start] : 0), right + ((!fiveLeft) ? nums[start] : 0), fiveLeft, chosen); | |
} | |
} | |
if (nums[start] % 3 == 0 && nums[start] % 5 != 0) { | |
if (!chosen) { | |
return split_fn(start + 1, nums, left + nums[start], right, false, true) || split_fn(start + 1, nums, left, right + nums[start], true, true); | |
} else { | |
return split_fn(start + 1, nums, left + ((!fiveLeft) ? nums[start] : 0), right + ((fiveLeft) ? nums[start] : 0), fiveLeft, chosen); | |
} | |
} | |
//standard case | |
return split_fn(start + 1, nums, left + nums[start], right, fiveLeft, chosen) || split_fn(start + 1, nums, left, right + nums[start], fiveLeft, chosen); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment