Count Subsets With Odd Sum
MediumP3Coding
Return the number of subsets of nums whose element sum is odd. Subsets are chosen by position, so equal values at different positions give different subsets. The empty subset has sum 0 and is not odd.
Example 1
- Input
- nums = [1,2,3]
- Output
- 4
- Why
- Odd-sum subsets: {1}, {3}, {1,2}, {2,3}.
Example 2
- Input
- nums = []
- Output
- 0
Example 3
- Input
- nums = [2,4,6]
- Output
- 0
Constraints
- 0 <= nums.length <= 50
- -10^6 <= nums[i] <= 10^6
- The answer fits in a 53-bit integer.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.