LeetCode Single Number III Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. For example: Given nums = , return . Note: The... Read More

# Tag Archives: 位运算

# LeetCode Single Number II

LeetCode 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 implement it without using... Read More

# LeetCode Counting Bits

LeetCode 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 should return . Follow... Read More

# LeetCode Number Complement

LeetCode 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 32-bit signed integer. You... Read More

# LeetCode Power of Four

LeetCode Power of Four Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it without... Read More

# LeetCode Power of Two

LeetCode Power of Two Given an integer, write a function to determine if it is a power of two. 判断一个数是否是2的幂次方。 递归或迭代等常规方法就不说了，可以参考LeetCode Power of... Read More

# LeetCode Find the Difference

LeetCode Find the Difference Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at a random position. Find the letter that was added in... Read More

# LeetCode Hamming Distance

LeetCode 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,... Read More

# LeetCode Reverse Bits

LeetCode Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow... Read More

# LeetCode Number of 1 Bits

LeetCode 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 00000000000000000000000000001011,... Read More