Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Could you do this in O(n) runtime?Continue reading “[Leetcode]421. Maximum XOR of Two Numbers in an Array”
[Leetcode]1558. Minimum Numbers of Function Calls to Make Target Array
Your task is to form an integer arrayContinue reading “[Leetcode]1558. Minimum Numbers of Function Calls to Make Target Array”nums
from an initial array of zerosarr
that is the same size asnums
. Return the minimum number of function calls to makenums
fromarr
. The answer is guaranteed to fit in a 32-bit signed integer.
[Leetcode]1022. Sum of Root To Leaf Binary Numbers
Given a binary tree, each node has valueContinue reading “[Leetcode]1022. Sum of Root To Leaf Binary Numbers”0
or1
. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is0 -> 1 -> 1 -> 0 -> 1
, then this could represent01101
in binary, which is13
. For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. Return the sum of these numbers.
[Leetcode]1286. Iterator for Combination
Design an Iterator class, which has: A constructor that takes a stringContinue reading “[Leetcode]1286. Iterator for Combination”characters
of sorted distinct lowercase English letters and a numbercombinationLength
as arguments. A function next() that returns the next combination of lengthcombinationLength
in lexicographical order. A function hasNext() that returnsTrue
if and only if there exists a next combination. Constraints:1 <= combinationLength <= characters.length <= 15
There will be at most10^4
function calls per test. It's guaranteed that all calls of the functionnext
are valid.
[Leetcode]260. Single Number III
Given an array of numbersContinue reading “[Leetcode]260. Single Number III”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. Example: Input:[1,2,1,3,2,5]
Output:[3,5]
[Leetcode]190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000Continue reading “[Leetcode]190. Reverse Bits”
[Leetcode problems]137. Single Number II
Given a non-empty 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 extra memory? Example 1: Input: [2,2,3,2] Output: 3Continue reading “[Leetcode problems]137. Single Number II”
[Leetcode problems]136. 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: 1Continue reading “[Leetcode problems]136. Single Number”