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”
Your task is to form an integer array
Continue reading “[Leetcode]1558. Minimum Numbers of Function Calls to Make Target Array”
nums from an initial array of zeros
arr that is the same size as
Return the minimum number of function calls to make
The answer is guaranteed to fit in a 32-bit signed integer.
Given a binary tree, each node has value
Continue reading “[Leetcode]1022. Sum of Root To Leaf Binary Numbers”
1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is
0 -> 1 -> 1 -> 0 -> 1, then this could represent
01101 in binary, which is
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.
Design an Iterator class, which has:
A constructor that takes a string
Continue reading “[Leetcode]1286. Iterator for Combination”
characters of sorted distinct lowercase English letters and a number
combinationLength as arguments.
A function next() that returns the next combination of length
combinationLength in lexicographical order.
A function hasNext() that returns
True if and only if there exists a next combination.
1 <= combinationLength <= characters.length <= 15
There will be at most
10^4 function calls per test.
It's guaranteed that all calls of the function
next are valid.
Given an array of numbers
Continue 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.
Reverse bits of a given 32 bits unsigned integer.
Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000
Continue reading “[Leetcode]190. Reverse Bits”
Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Input: [2,2,3,2] Output: 3
Continue reading “[Leetcode problems]137. Single Number II”