Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Note:
- Each of the array element will not exceed 100.
- The array size will not exceed 200.
Example 1:
1 | Input: [1, 5, 11, 5] |
Example 2:
1 | Input: [1, 2, 3, 5] |
解法1:动态规划
1 | class Solution { |
时间复杂度:与nums.size()和target都相关。
解法2
1 | class Solution { |
时间复杂度:仅仅与nums.size()相关