Skip to content

Commit 5b0aa45

Browse files
Merge pull request #1701 from CodingTestStudy2/이진희
[이진희] Day24
2 parents 05c0fe5 + 91a272e commit 5b0aa45

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
3+
1. 아이디어 : 수식을 만족하는 x의 값 구하기
4+
5+
2. 시간복잡도 : O(200) // n=100 k=100
6+
7+
3. 자료구조/알고리즘 : 수학
8+
9+
*/
10+
11+
class Solution {
12+
public int sumOfGoodIntegers(int n, int k) {
13+
// x는 양수
14+
// k+n >= x >= n-k
15+
int ans = 0;
16+
int start = n-k>0 ? n-k : 1;
17+
int end = n+k;
18+
19+
for(int i = start; i<= end; i++) {
20+
if((n&i) == 0) ans+=i;
21+
}
22+
23+
return ans;
24+
}
25+
}

0 commit comments

Comments
 (0)