Pre-defined Methods
- Integer.toBinaryString(int n) return binary string
- Integer.toBinaryString(int n).toCharArray() directly to array.
思路
知道可以用位运算,但是不会应用,参考discussion
https://discuss.leetcode.com/topic/57007/java-tle-question/2
Use string and array to do compare one by one. There is no unsigned problem.
- Use %2 to get the bit. But cannot use for negtive. But learn about True Code, Complemental Code and Ones-complement Code
关于位运算
>>
右移,和>>>
无符号右移的区别。
正数右移,高位用0补,负数右移,高位用1补,当负数使用无符号右移时,用0进行部位(自然而然的,就由负数变成了正数了)
http://blog.csdn.net/xiaochunyong/article/details/7748713