05 2016 档案
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the fo
阅读全文
摘要:题目: 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
阅读全文
摘要:这道题如下: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = "aabcc",s2 = "dbbca", When s3 = "aadbbcbca
阅读全文
摘要:这道题如下: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example,Given n = 3, your program should ret
阅读全文
摘要:backtracing是一个常用的解法。之前遇到一个题目,求一个集合的子集, 例如给定{1,2,3,4,5},求其大小为3的子集。 利用backtracing可以较快的给出答案。 然而,该题还有一个变种,即如果集合中有重复的元素怎么办。 例如,{1,1,1,2,2,3,4,5} 依然使用backtr
阅读全文
摘要:上一篇文章讲了该题的一个解法。后来又发现一个更好的解法。 首先依旧考虑一个升序的数列,例如1,2,3,4,5。那么它的最大矩形显然是有5种可能,即 1*5,2*4,3*3,4*2,1*5。所以最大的矩形为9。那么显然不可能是升序的数列。 依据以下几条规则对其进行处理。 有栈stack和待处理数组a[
阅读全文
摘要:直方图上的最大矩形。这道题很有意思。研究了半天才研究出来是个什么意思。 首先看题目: Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, fin
阅读全文
摘要:题目: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). For example,S = "ADOB
阅读全文
摘要:首先给出题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) Y
阅读全文
摘要:题目为: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,
阅读全文
摘要:N皇后是一个十分经典的问题。 这题一个经典的解法就是回溯法。 一开始使用回溯法的话。陷入了两个误区。 第一,每次回溯都从第一个点开始计算,其实完全没必要。 第二,每次回溯都将当前解空间复制一遍。其实也没有必要。 上网搜了一下解法。核心思想为,因为N皇后问题限制每行只能放一个皇后。所以,考虑以行为维度
阅读全文
摘要:Given a collection of distinct numbers, return all possible permutations. For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3
阅读全文
摘要:题目: Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your m
阅读全文

浙公网安备 33010602011771号