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 |
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, each node has value 0 or 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 13. | |
| 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. | |
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 stream of integers and a window size, calculate the moving average of all integers in the sliding window. | |
| Example: | |
| MovingAverage m = new MovingAverage(3); | |
| m.next(1) = 1 | |
| m.next(10) = (1 + 10) / 2 | |
| m.next(3) = (1 + 10 + 3) / 3 | |
| m.next(5) = (10 + 3 + 5) / 3 |
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 pattern and a string str, find if str follows the same pattern. | |
| Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. | |
| Example 1: | |
| Input: pattern = "abba", str = "dog cat cat dog" | |
| Output: true | |
| 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
| """ | |
| Given two binary search trees root1 and root2. | |
| Return a list containing all the integers from both trees sorted in ascending order. | |
| Example 1: | |
| Input: root1 = [2,1,4], root2 = [1,0,3] | |
| Output: [0,1,1,2,3,4] |
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, find out whether there are two distinct indices i and j in the array such that the | |
| absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k. | |
| Example 1: | |
| Input: nums = [1,2,3,1], k = 3, t = 0 | |
| Output: true | |
| Example 2: | |
| Input: nums = [1,0,1,1], k = 1, t = 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
| """ | |
| A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so | |
| that each letter appears in at most one part, and return a list of integers representing the size of these parts. | |
| Example 1: | |
| Input: S = "ababcbacadefegdehijhklij" | |
| Output: [9,7,8] |