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:
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:
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
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
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
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
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
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
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
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
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
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
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
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 { } 解答思路:一
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
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