Odd-Even Count Difference
EasyP3Coding
Return the absolute difference between the number of odd elements and the number of even elements in nums. Zero is even.
Example 1
- Input
- nums = [1,2,3]
- Output
- 1
- Why
- Two odd elements, one even element: |2 - 1| = 1.
Example 2
- Input
- nums = [2,4,6,8]
- Output
- 4
Example 3
- Input
- nums = []
- Output
- 0
Constraints
- 0 <= nums.length <= 10^5
- -10^9 <= nums[i] <= 10^9
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.