Jayakrishna14

Untitled

Jun 3rd, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. class Solution {
  2. public boolean checkEqualPartitions(int[] nums, long target) {
  3. int n = nums.length;
  4. for(int i = 0; i < (1 << n); i++) {
  5. long prod1 = 1, prod2 = 1;
  6. for(int j = 0; j < n; j++) {
  7. if(((i >> j) & 1) == 1) {
  8. prod1 *= nums[j];
  9. } else {
  10. prod2 *= nums[j];
  11. }
  12.  
  13. if(prod1 > target || prod2 > target) {
  14. break;
  15. }
  16. }
  17.  
  18. if(prod1 == target && prod2 == target) {
  19. return true;
  20. }
  21. }
  22.  
  23. return false;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment