位运算
srping123
这个作者很懒,什么都没留下…
展开
-
LeetCode(一)--461.Hamming Distance&476.Number Complement 位运算
Hamming Distance 题目要求如下 The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hammi转载 2017-08-11 17:02:25 · 208 阅读 · 0 评论 -
LeetCode(九)231. Power of Two&405. Convert a Number to Hexadecimal
231.Power of Two题目要求判断一个数是否是2的乘方。 可以使用循环求解,也可以用位运算如下public class Solution { public boolean isPowerOfTwo(int n) { return n>0 && ((n & (n-1)) == 0); }}使用如下代码可以求解一个数的二进制中1的个数 int ans = 0转载 2017-08-18 17:20:41 · 189 阅读 · 0 评论