標籤:: BitManipulation

0

Counting Bits

Counting BitsGiven 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. For example:

0

Maximum Product of Word Lengths

Maximum Product of Word LengthsGiven a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word w

0

Single Number III

Single Number IIIGiven 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 examp

0

Bitwise AND of Numbers Range

Bitwise AND of Numbers RangeGiven 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 sho

0

Repeated DNA Sequences

Repeated DNA SequencesAll DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences

0

Single Number II

Single Number IIGiven 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 compl

0

Subsets

SubsetsGiven a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example:If nums = [1,2,3], a solution is: 12345678910[ [3],

0

Hamming Distance

Hamming DistanceThe 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

0

Convert a Number to Hexadecimal

Convert a Number to HexadecimalGiven an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used. Note: All letters in hexadecimal (a-f) must b

0

Binary Watch

Binary WatchA binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least signifi

0

Sum of Two Integers

Sum of Two IntegersCalculate the sum of two integers a and b, but you are not allowed to use the operator + and -. For Example:1Given a = 1 and b = 2, return 3. 提示 解題應用 BitManipulation XOR,AND

0

Power of Four

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

0

Missing Number

Missing NumberGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array. For example:1Given nums = [0, 1, 3] return 2. Note: Your algorithm sh

0

Power of Two

Power of TwoGiven an integer, write a function to determine if it is a power of two. 提示 解題應用 Math 規律觀查 BitManipulation AND Default:123func isPowerOfTwo(n int) bool { } 解答思路:一

0

Majority Element

Majority ElementGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the major

0

Single Number

Single NumberGiven 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