Untitled
unknown
plain_text
a month ago
715 B
1
Indexable
Never
class Solution { public boolean canPartition(int[] nums) { Map<Integer, Integer> mp = new HashMap<>(); int len = nums.length; int cnt = 0; for (int i = 0; i < len; i++) { Set<Integer> st=new HashSet<>(); cnt += nums[i]; for (Integer j : mp.keySet()) { if (mp.getOrDefault(j, -1) != -1) { st.add(nums[i]+j); } } st.add(nums[i]); for(Integer j:st) { mp.put(j,1); } } if (cnt % 2 != 0 || mp.getOrDefault(cnt / 2, -1) == -1) return false; return true; } }
Leave a Comment