Skip to content

Commit abde96d

Browse files
authored
Create 3954. Sum of Compatible Numbers in Range I.py
1 parent 59ebae8 commit abde96d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
3+
'''
4+
1. 아이디어 :
5+
-
6+
7+
2. 시간복잡도 :
8+
O(2k)
9+
10+
3. 자료구조/알고리즘 :
11+
-
12+
13+
'''
14+
class Solution:
15+
def sumOfGoodIntegers(self, n: int, k: int) -> int:
16+
ans = 0
17+
x = max(1, n-k)
18+
while abs(n-x) <= k:
19+
if n&x == 0:
20+
ans += x
21+
x+=1
22+
return ans

0 commit comments

Comments
 (0)