Given a digit string, return all possible letter combinations that thenumber could represent. A mapping of digit to letters (just like on the telephone buttons) isgiven below. Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf","cd", "ce", "cf"].
Given n pairs of parentheses, write a function to generate allcombinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()"
Given a string S and a string T, count the number of distinctsubsequences of T in S. A subsequence of a string is a new string which is formed from theoriginal string by deleting some (can be none) of the characterswithout disturbing the relative positions of the remaining characters.(ie, "ACE" i...
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", returnfalse.
A message containing letters from A-Z is being encoded to numbersusing the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containingdigits, determine the total number of ways to decode it. For example, Given encoded message "12", it could be decoded as "AB"(1...
Given a m x n grid filled with non-negative numbers, find a path fromtop left to bottom right which minimizes the sum of all numbers alongits path. Note: You can only move either down or right at any point in time.
A robot is located at the top-left corner of a m x n grid (marked'Start' in the diagram below). The robot can only move either down or right at any point in time. Therobot is trying to reach the bottom-right corner of the grid (marked'Finish' in the diagram below). How many possible unique paths ...
Find the contiguous subarray within an array (containing at least onenumber) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3]has the largest product = 6.
Find the contiguous subarray within an array (containing at least onenumber) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguoussubarray [4,−1,2,1] has the largest sum = 6.
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element andreturn its index. The array may contain multiple peaks, in that case return the index toany one of the peaks is fine. You may imagine that num[-1] = num[n] = -∞. F...
Suppose a sorted array is rotated at some pivot unknown to youbeforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array returnits index, otherwise return -1. You may assume no duplicate exists in the array.
Given a sorted array of integers, find the starting and endingposition of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. For example, Given [5, 7, 7, 8, 8, 10] and target value 8, return [3,4].
Recover Binary Search Tree Two elements of a binary search tree (BST) are swapped by mistake. 递归法 思路 这道题是要求恢复一颗有两个元素调换错了的二叉查找树。中序遍历BST 然后找到逆序。有两种情况需要考虑: 两个错位的节点是相邻的父子树关系, 那么找到第一个先序遍历逆序的两个节点 两个错位的节点不是父子...
Given a binary tree, determine if it is a valid binary search tree(BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than thenode's key. The right subtree of a node contains only nodes with keysgreater than the node's key. Both the left and ri...
There are a total of n courses you have to take, labeled from 0 to n -1. Some courses may have prerequisites, for example to take course 0 youhave to first take course 1, which is expressed as a pair: [0,1] Given the total number of courses and a list of prerequisite pairs, isit possible for you ...
Given an directed graph, a topological order of the graph nodes isdefined as follow: For each directed edge A -> B in graph, A must before B in the orderlist. The first node in the order can be any node in the graph with nonodes direct to it. Find any topological order for the given graph.