classSolution{public:longlongmaxNumber(longlongn){// assume n = 0b00...11???// x = 0b00...01111// since y = 0b00...10000 is in [x, n]// and x & y = 0constinti=63-__builtin_clzll(n);return(1L<<i)-1;}};
1 2 3 4 5 6 7 8 910
classSolution{publiclongmaxNumber(longn){// assume n = 0b00...11???// x = 0b00...01111// since y = 0b00...10000 is in [x, n]// and x & y = 0finalinti=63-Long.numberOfLeadingZeros(n);return(1L<<i)-1;}}
1234567
classSolution:defmaxNumber(self,n:int)->int:# assume n = 0b00...11???# x = 0b00...01111# since y = 0b00...10000 is in [x, n]# and x & y = 0return(1<<n.bit_length()-1)-1