08 2016 档案
摘要:Unique Binary Search Trees:求生成二叉排序树的个数。 Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example,Given n
阅读全文
摘要:问题描述: Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", retu
阅读全文
摘要:ReverseLinkedList: ReverseLinkedList2: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NU
阅读全文
摘要:问题描述: A message containing letters from A-Z is being encoded to numbers using the following mapping: Given an encoded message containing digits, deter
阅读全文
摘要:问题描述: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the tot
阅读全文
摘要:问题描述: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible repres
阅读全文
摘要:/* w代表物品重量,v代表物品价值,c代表背包最大能容纳重量 res[i][j]代表背包可以选择前i个物品,最大容量为j时候的最大价值 res[i-1][j] if(w[i-1] > j) res[i][j] = max((res[i-1][j-w[i-1]]+v[i-1]), res[i-1][j]) else **/ public c...
阅读全文
摘要:问题描述: Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserv
阅读全文
摘要:问题描述: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. For example, given the fol
阅读全文
摘要:问题描述: Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in th
阅读全文
摘要:问题描述:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of element
阅读全文
摘要:Remove Duplicates from Sorted List : Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1
阅读全文
摘要:问题描述: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where
阅读全文
摘要:问题描述: Given a set of distinct integers, nums, return all possible subsets. Note: The solution set must not contain duplicate subsets. For example,If n
阅读全文
摘要:问题描述: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which th
阅读全文
摘要:问题描述:给定字符串S,子串T,求S中包含T的最小窗口 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
阅读全文
摘要:问题描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order
阅读全文
摘要:问题描述:矩阵每一行有序,每一行的最后一个元素小于下一行的第一个元素,查找。 算法分析:这样的矩阵其实就是一个有序序列,可以使用折半查找算法。 问题描述:二维矩阵行有序,列有序,进行查找。 算法分析:有两种方法,一种是将矩阵按中心点分成左上,左下,右上,右下,四部分,进行递归查找。 还有一种比较巧妙
阅读全文
摘要:问题描述: 题目描述Edit DistanceGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counte
阅读全文
摘要:问题描述:把一个集合的单词按照每行L个字符放,每行要两端对齐,如果空格不能均匀分布在所有间隔中,那么左边的空格要多于右边的空格,最后一行靠左对齐。 words: ["This", "is", "an", "example", "of", "text", "justification."]L: 16.
阅读全文
摘要:算法分析:利用折半查找,降低算法复杂度。前面求x得y次幂,也是将y/2,都是为了降低复杂度。
阅读全文
摘要:问题描述: Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100".
阅读全文
摘要:问题描述:一个数组每一位代表一个数字的每一位。数字高位在数组的低位。求数字加1后得到新数组。 算法分析:要从数组的高位到低位进行遍历。
阅读全文
摘要:问题描述: Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true
阅读全文
摘要:问题描述:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its p
阅读全文
摘要:UniquePaths:给定m*n矩阵,从(0,0)到(m-1,n-1)路径条数。只能向下向右走。 算法分析:这和爬楼梯问题很像,到(m,n)的路径数是到(m-1,n)和(m,n-1)路径和。第一行,第一列,为边界条件。 UniquePaths2:在上一题基础上,矩阵为1的点是障碍。求路径数。
阅读全文
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string. If the last word
阅读全文
摘要:Merge Interval: Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15
阅读全文
摘要:SpiralMatrix: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example,Given the following
阅读全文
摘要:问题描述: ind 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皇后的规则:任意两个皇后不在同一行,不在同一列,不在同一斜线上。 算法分析:这种问题就用回溯法。深度搜索然后回溯。用一个数组记录每一行皇后的位置,下标代表行,值代表列。对行深度搜索。 NQueens2:计算有多少种解决方案。 算法分析:用一个成员变量来记录解决方案的个数。
阅读全文
摘要:问题描述: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1-
阅读全文
摘要:算法分析:很显然用递归。但是直接用递归会造成栈溢出,时间复杂度是o(n)。所以要用分治思想,时间复杂度是o(logN)。
阅读全文
摘要:问题描述:给定一个字符串数组,返回变形词组,变形词是指字母一样但顺序不一样的词。 Given an array of strings, group anagrams together. For example, given: ["eat", "tea", "tan", "ate", "nat", "
阅读全文
摘要:public class RotateImage { public void rotate(int[][] matrix) { if(matrix.length == 1 && matrix[0].length == 1) { return; } int n = matrix.length; for(int i = 0; i < n-1; i ++) { ...
阅读全文
摘要:JumpGame:给定一个非负整数数组,开始在第一个位置,每个位置上的数字代表最大可以跳跃的步数,判断能不能跳到最后一个位置。 例如:A=[2,3,1,1,4],在位置0处,可以跳一步到位置1,位置1跳3步到位置4. JumpGame2:给定一个非负整数数组,开始在第一个位置,每个位置上的数字代表最
阅读全文
摘要:WildcardMatching:通配符匹配 算法分析: 1. 二个指针i, j分别指向字符串、匹配公式。 2. 如果匹配,直接2个指针一起前进。 3. 如果匹配公式是*,在字符串中依次匹配即可。 注意记录上一次开始比较的位置 Implement wildcard pattern matching
阅读全文
摘要:问题描述:给定两个字符串,返回他们的乘积。
阅读全文
摘要:问题描述: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after ra
阅读全文
摘要:算法分析: 堆排序的思想是利用数据结构--堆。具体的实现细节: 1. 构建一个最大堆。对于给定的包含有n个元素的数组A[n],构建一个最大堆,从最下层最右边的非终端结点开始构建,将它与其孩子进行比较和若有必要的互换,调整这个堆结构,使其满足最大堆的特性。当为了满足最大堆特性时,堆结构发生变化,此时递
阅读全文

浙公网安备 33010602011771号