Skip to content

Commit c21dafb

Browse files
authored
Create Sum of Values at Indices With K Set Bits.java
1 parent 80259e4 commit c21dafb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public int sumIndicesWithKSetBits(List<Integer> nums, int k) {
3+
return IntStream.range(0, nums.size())
4+
.filter(idx -> Integer.bitCount(idx) == k)
5+
.map(idx -> nums.get(idx))
6+
.sum();
7+
}
8+
}

0 commit comments

Comments
 (0)