Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public boolean checkEqualPartitions(int[] nums, long target) {
- int n = nums.length;
- for(int i = 0; i < (1 << n); i++) {
- long prod1 = 1, prod2 = 1;
- for(int j = 0; j < n; j++) {
- if(((i >> j) & 1) == 1) {
- prod1 *= nums[j];
- } else {
- prod2 *= nums[j];
- }
- if(prod1 > target || prod2 > target) {
- break;
- }
- }
- if(prod1 == target && prod2 == target) {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment