2 lines easy Java solution


  • 0
    while (n > m) n ^= (n & -n);
    return n;
    

    If u don't wanna lose the input value.

    int res = n;
    while (res > m) 
        res ^= (res & -res);
    return res;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.