位运算
文章平均质量分 65
likecool21
这个作者很懒,什么都没留下…
展开
-
利用位运算判断整数的正负
挺有趣的题:给定一个整数,判断其正负,正数返回1,复数返回-1,0返回0.要求只能用位运算符和加号,且不能用循环判断等控制语句。 想到的代码是类似递归的,感觉还是挺笨的: int sign(int x) { //Right move 31 bits, if x is non-negative, then a=0x00000000 //if x is negative, then a =原创 2013-04-20 22:15:59 · 7140 阅读 · 2 评论 -
LeetCode刷题笔录Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2014-05-03 09:58:12 · 638 阅读 · 0 评论