Jun 26, 2020 02:25:03 AM
https://leetcode.com/problems/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 Hamming distance.
Note:
0 ≤ x
, y
< 231.
Example:
Input: x = 1, y = 4
Output: 2
Explanation:
1 (0 0 0 1)
4 (0 1 0 0)
↑ ↑
The above arrows point to positions where the corresponding bits are different.
Tags: Algorithm BitManipulation Golang
Posted in 算法 | 2 Comments
Jun 26, 2020 02:19:00 AM
https://leetcode.com/problems/number-of-1-bits/
Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight).
Example 1:
Input: 00000000000000000000000000001011
Output: 3
Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.
Tags: Algorithm BitManipulation Golang
Posted in 算法 | 1 Comments
Apr 24, 2020 01:29:45 AM
https://leetcode.com/problems/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.
Example 1:
Input: [5,7]
Output: 4
Example 2:
Input: [0,1]
Output: 0
Tags: Algorithm Golang BitManipulation
Posted in 算法 | 0 Comments
Apr 02, 2020 02:52:36 AM
https://leetcode.com/problems/single-number/
Given a non-empty 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 memory?
Example 1:
Input: [2,2,1]
Output: 1
Tags: Algorithm Golang BitManipulation array
Posted in 算法 | 1 Comments