Java don`t have type unsigned int!Could not change unsigned int to long in java?


  • 0
    Y
    class Solution {
    public long reverseBits(int n) {
    	long ret = 0;
    	long t = 1;
    	long k = 2147483648l;
    	int cnt = 32;
    	
    	while((cnt--) != 0) {
    		if((n & k) == k)
    			ret += t;
    		
    		t <<= 1;
    		k >>= 1;
    	}
    	return ret;
    }
    

    }


  • 0
    J

    Your solution is correct.

    Return type should be int, and you can cast ret to an int at the end.


Log in to reply
 

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