
public class LCA {
public int getLCA(int a, int b) {
// <<左移 >>右移
if(a == b) {
return a;
}
while(a != b) {
a = a > b ? a>>1 : a;
b = b > a ? b>>1 : b;
}
return a;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
int j = sc.nextInt();
LCA c = new LCA();
System.out.println(c.getLCA(i,j));
}
}
744

被折叠的 条评论
为什么被折叠?



