https://leetcode.com/problems/partition-equal-subset-sum/
public class Solution {
public boolean canPartition(int[] nums) {
int sum = 0;
for (int i=0; i<nums.length; i++) {
sum += nums[i];
}
if (sum % 2 == 1) {
return false;
}
sum /= 2;
Set st = new HashSet();
st.add(0);
for (int i=0; i<nums.length; i++) {
Set tmpSt = new HashSet();
Iterator itr = st.iterator();
while (itr.hasNext()) {
int newVal = (int)itr.next() + nums[i];
if (newVal == sum) {
return true;
}
if (newVal < sum) {
tmpSt.add(newVal);
}
}
st.addAll(tmpSt);
}
return false;
}
}