Java solution using Integer.reverse()


  • 0
    M
    public class Solution {
        // you need treat n as an unsigned value
        public int reverseBits(int n) {
            if(n<=Integer.MAX_VALUE) {
                return Integer.reverse(n);
            } else {
                return Integer.reverse(n-Integer.MAX_VALUE);
            }
        }
    }
    

Log in to reply
 

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