Given the root of a binary tree, invert the tree, and return its root.
Example 1:
1 | Input: root = [4,2,7,1,3,6,9] |
Example 2:
1 | Input: root = [2,1,3] |
Example 3:
1 | Input: root = [] |
Given the root of a binary tree, invert the tree, and return its root.
Example 1:
1 | Input: root = [4,2,7,1,3,6,9] |
Example 2:
1 | Input: root = [2,1,3] |
Example 3:
1 | Input: root = [] |
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
1 | Input: [1,2,3,1] |
Example 2:
1 | Input: [1,2,3,4] |
Example 3:
1 | Input: [1,1,1,3,3,4,3,2,4,2] |
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
Example 1:
1 | Input: nums = [2,3,2] |
Example 2:
1 | Input: nums = [1,2,3,1] |
Example 3:
1 | Input: nums = [0] |
1 | In March 2020, people were encouraged to stay at home. |
A trie (pronounced as “try”) or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.
Implement the Trie class:
Trie() Initializes the trie object.
void insert(String word) Inserts the string word into the trie.
boolean search(String word) Returns true if the string word is in the trie (i.e., was inserted before), and false otherwise.
boolean startsWith(String prefix) Returns true if there is a previously inserted string word that has the prefix prefix, and false otherwise.
Example 1:
1 | Input |