位运算
Wu_uuuu
这个作者很懒,什么都没留下…
展开
-
Leetcode--476. Number Complement
一、题目Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note: The given integer is guaranteed to fit within the range of a原创 2017-06-30 15:48:49 · 209 阅读 · 0 评论 -
Leetcode--Add to List 371. Sum of Two Integers
题目Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example: Given a = 1 and b = 2, return 3. 不使用+ - 实现加法思路位运算来实现代码递归版本class Solution { public: int ge原创 2017-08-02 10:34:12 · 237 阅读 · 0 评论 -
Leetcode--Add to List 201. Bitwise AND of Numbers Range
题目Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.For example, given the range [5, 7], you should return 4. 数字范围位相与思路直接平移m和n,每次向右移一原创 2017-07-01 15:34:22 · 276 阅读 · 0 评论 -
Leetcode--191. Number of 1 Bits
题目Write a function that takes an unsigned integer and returns the number of ’1’ bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11’ has binary representation 00000000000原创 2017-07-01 13:18:16 · 327 阅读 · 0 评论 -
Leetcode--137.Single Number II
题目Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you原创 2017-06-30 20:32:07 · 315 阅读 · 0 评论 -
Leetcode--136.Single Number
题目Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra原创 2017-06-30 20:01:51 · 240 阅读 · 0 评论 -
Leetcode--89. Gray Code
题目The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gra原创 2017-06-30 19:26:20 · 333 阅读 · 0 评论 -
Leetcode--231、Power of Two
题目Given an integer, write a function to determine if it is a power of two.思路如果是2的幂,则二进制的所有位中,有且仅有一个1。 可以复用 “Number of 1 Bits” 中的函数,计算出1的个数,如果为1,则返回true, 不为1,返回 false。 还有更巧妙的办法。如果一个数是2的幂,则它的二进制最高位必然为1原创 2017-06-30 17:25:29 · 217 阅读 · 0 评论 -
Leetcode--268. Missing Number
一、题目Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in原创 2017-06-30 16:26:58 · 247 阅读 · 0 评论 -
Leetcode--338. Counting Bits
题目Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array.Example: For num = 5 you原创 2017-08-27 20:50:31 · 268 阅读 · 0 评论