[Top]
This file contains 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
""" | |
Description: | |
Implement an iterator over a binary search tree (BST). Your iterator will be | |
initialized with the root node of a BST. Calling next() will return the next smallest | |
number in the BST. The methods, next() and hasNext(), should run in average O(1) time | |
and uses O(h) memory, where h is the height of the tree. | |
""" | |
class TreeNode: | |
def __init__(self, x): |
This file contains 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
""" | |
Description: | |
Design a data structure that supports the following two operations: | |
- void addWord(word) | |
- bool search(word) | |
search(word) can search a literal word or a regular expression string containing only | |
letters a-z or .. A . means it can represent any one letter. You may assume that all | |
words are consist of lowercase letters a-z. | |
Example: |
This file contains 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
""" | |
Description: | |
Given a nested list of integers, implement an iterator to flatten it. Each element is | |
either an integer, or a list -- whose elements may also be integers or other lists. | |
Use API below to implement the class: | |
""" | |
#class NestedInteger: | |
# def isInteger(self): | |
# """ |
This file contains 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
""" | |
Description: | |
Design an algorithm to serialize and deserialize a binary tree. There is no restriction | |
on how your serialization/deserialization algorithm should work. You just need to | |
ensure that a binary tree can be serialized to a string and this string can be | |
deserialized to the original tree structure. | |
- Do not use class member/global/static variables to store states. Your serialize and | |
deserialize algorithms should be stateless. | |
Example: |
This file contains 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
""" | |
Description: | |
The API: int read4(char *buf) reads 4 characters at a time from a file. The return | |
value is the actual number of characters read. For example, it returns 3 if there is | |
only 3 characters left in the file. By using the read4 API, implement the function int | |
read(char *buf, int n) that reads n characters from the file. The read function may be | |
called multiple times. | |
Examples: | |
Input: "abc" in a file |
This file contains 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
""" | |
Description: | |
The API: int read4(char *buf) reads 4 characters at a time from a file. The return | |
value is the actual number of characters read. For example, it returns 3 if there is | |
only 3 characters left in the file. By using the read4 API, implement the function int | |
read(char *buf, int n) that reads n characters from the file. The read function will be | |
called only once. | |
Examples: | |
Input: "abc" in a file, n = 4 |
This file contains 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
""" | |
Description: | |
Given an integer array nums, find the contiguous subarray (containing at least one | |
number) which has the largest sum and return its sum. | |
Example: | |
Input: [-2,1,-3,4,-1,2,1,-5,4] | |
Output: 6 -- [4, -1, 2, 1] => 6 | |
""" |
This file contains 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
""" | |
Description: | |
You are climbing a stair case. It takes n steps to reach to the top. Each time you can | |
either climb 1 or 2 steps. In how many distinct ways can you climb to the top? | |
- Given n will be a positive integer. | |
Examples: | |
Input: 2 | |
Output: 2 -- 1 + 1 and 2 |
This file contains 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
""" | |
Description: | |
In a given array nums of positive integers, find three non-overlapping subarrays with | |
maximum sum. Each subarray will be of size k, and we want to maximize the sum of all | |
3*k entries. Return the result as a list of indices representing the starting position | |
of each interval (0-indexed). If there are multiple answers, return the | |
lexicographically smallest one. | |
- nums length will be between 1 and 20000. | |
- nums[i] will be between 1 and 65535. | |
- k will be between 1 and floor(nums.length / 3). |