2859. Sum of Values at Indices With K Set Bits
You are given a 0-indexed integer array
nums
and an integerk
.Return an integer that denotes the sum of elements in
nums
whose corresponding indices have exactlyk
set bits in their binary representation.The set bits in an integer are the
1
‘s present when it is written in binary.
- For example, the binary representation of
21
is10101
, which has3
set bits.
1 | class Solution { |