forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximizingXOR.java
More file actions
37 lines (31 loc) · 758 Bytes
/
MaximizingXOR.java
File metadata and controls
37 lines (31 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
/*
* Complete the function below.
*/
static int maxXor(int l, int r) {
int max = 0;
for(int a=l;a<=r;a++){
for(int b=a;b<=r;b++){
int c = a^b;
if(c>max)
max = c;
}
}
return max;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int res;
int _l;
_l = Integer.parseInt(in.nextLine());
int _r;
_r = Integer.parseInt(in.nextLine());
res = maxXor(_l, _r);
System.out.println(res);
}
}