This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a binary tree, find its minimum depth. | |
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. | |
Note: A leaf is a node with no children. | |
Input: root = [3,9,20,null,null,15,7] | |
Output: 2 | |
Example 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Design a data structure that accepts a stream of integers and checks if it has a pair of integers that sum up to a particular value. | |
Implement the TwoSum class: | |
TwoSum() Initializes the TwoSum object, with an empty array initially. | |
void add(int number) Adds number to the data structure. | |
boolean find(int value) Returns true if there exists any pair of numbers whose sum is equal to value, otherwise, it returns false. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a list of intervals, remove all intervals that are covered by another | |
interval in the list. | |
Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d. | |
After doing so, return the number of remaining intervals. | |
Example 1: | |
Input: intervals = [[1,4],[3,6],[2,8]] | |
Output: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given an array of integers nums and an integer k, return the number of | |
unique k-diff pairs in the array. | |
A k-diff pair is an integer pair (nums[i], nums[j]), where the following are | |
true: | |
0 <= i, j < nums.length | |
i != j | |
a <= b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. | |
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next | |
station (i+1). You begin the journey with an empty tank at one of the gas stations. | |
Return the starting gas station's index if you can travel around the circuit once in the clockwise direction, | |
otherwise return -1. | |
Note: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""" | |
An integer has sequential digits if and only if each digit in the number is one more than the previous digit. | |
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. | |
Example 1: | |
Input: low = 100, high = 300 | |
Output: [123,234] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word | |
(last word means the last appearing word if we loop from left to right) in the string. | |
If the last word does not exist, return 0. | |
Note: A word is defined as a maximal substring consisting of non-space characters only. | |
Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a node in a binary search tree, find the in-order successor of that node in the BST. If that node has no | |
in-order successor, return null. | |
The successor of a node is the node with the smallest key greater than node.val. | |
You will have direct access to the node but not to the root of the tree. Each node will have a reference to its | |
parent node. Below is the definition for Node: | |
class Node { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Compare two version numbers version1 and version2. | |
If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. | |
You may assume that the version strings are non-empty and contain only digits and the . character. | |
The . character does not represent a decimal point and is used to separate number sequences. | |
For instance, 2.5 is not "two and a half" or "half way to version three", it is the fifth second-level revision of | |
the second first-level revision. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used | |
and each combination should be a unique set of numbers. | |
Note: | |
All numbers will be positive integers. | |
The solution set must not contain duplicate combinations. | |
Example 1: | |
Input: k = 3, n = 7 |