Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
Example 1:
1 | Input: nums = [100,4,200,1,3,2] |
Example 2:
1 | Input: nums = [0,3,7,2,5,8,4,6,0,1] |
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
Example 1:
1 | Input: nums = [100,4,200,1,3,2] |
Example 2:
1 | Input: nums = [0,3,7,2,5,8,4,6,0,1] |
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Example 1:
1 | Input: "A man, a plan, a canal: Panama" |
Example 2:
1 | Input: "race a car" |
Say you have an array for which the ith element is the price of a given stock on day i.
If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.
Note that you cannot sell a stock before you buy one.
Example 1:
1 | Input: [7,1,5,3,6,4] |
Example 2:
1 | Input: [7,6,4,3,1] |
Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.
Example 1:
1 | Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] |
Example 2:
1 | Input: preorder = [-1], inorder = [-1] |
Given a binary tree, collect a tree’s nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty.
Example:
1 | Input: [1,2,3,4,5] |
Explanation:
1 | 1. Removing the leaves [4,5,3] would result in this tree: |