Encryption Scheme II
EasyP3Coding
bits contains only 0 and 1. Return the sum of the 1-based positions (index plus one) of all the elements that equal 0. If there are no zeros, return 0.
Example 1
- Input
- bits = [1,0,0,1,0]
- Output
- 10
- Why
- Zeros are at positions 2, 3 and 5; 2 + 3 + 5 = 10.
Example 2
- Input
- bits = [0,0,0]
- Output
- 6
Example 3
- Input
- bits = [1,1,1]
- Output
- 0
Constraints
- 0 <= bits.length <= 10^5
- bits[i] is 0 or 1
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.