Skip to content

Commit 2f55b64

Browse files
authored
[20251217] PGM / LV2 / 2개 이하로 다른 비트 / 이인희
1 parent 13ea91f commit 2f55b64

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public long solution(long[] numbers) {
6+
ArrayList<Long> answers = new ArrayList<>();
7+
8+
for(long num: numbers){
9+
long now = num + 1;
10+
while(true){
11+
if(isOneOrTwoDifference(num, now)){
12+
answers.add(now);
13+
break;
14+
}
15+
now++;
16+
}
17+
}
18+
return answers.stream()
19+
.mapToLong(Long::longValue)
20+
.toArray();
21+
}
22+
23+
private boolean isOneOrTwoDifference(long a, long b){
24+
long diff = a ^ b;
25+
int count = 0;
26+
while(diff > 0){
27+
if((diff & 1) == 1){
28+
count++;
29+
}
30+
if(count > 2){
31+
return false;
32+
}
33+
34+
diff >>= 1;
35+
}
36+
return true;
37+
}
38+
}
39+
40+
```

0 commit comments

Comments
 (0)