728x90
https://leetcode.com/problems/sum-of-values-at-indices-with-k-set-bits/
class Solution:
def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:
sum = 0
for i in range(len(nums)):
if bin(i)[2:].count('1') == k:
sum = sum + nums[i]
return sum
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2703. Return Length of Arguments Passed (0) | 2024.02.02 |
---|---|
[Leetcode] 9. Palindrome Number (0) | 2024.02.02 |
[Leetcode] 1141. User Activity for the Past 30 Days I (0) | 2023.09.06 |
[Leetcode] 1978. Employees Whose Manager Left the Company (0) | 2023.09.05 |
[Leetcode] 1075. Project Employees I (0) | 2023.09.04 |