上一页 1 2 3 4 5 6 ··· 10 下一页
摘要: Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[[0,0,0],[0, 阅读全文
posted @ 2012-10-23 00:30 ETCOW 阅读(255) 评论(0) 推荐(0) 编辑
摘要: M*N grids from top-left to bottom-right find all the paths. 1 public static int UniquePaths(int m, int n) 2 { 3 int ret = 0; 4 FindAllPaths(m, n, ref ret); 5 return ret; 6 } 7 8 public static void FindAllPaths(int m, int n, ref int... 阅读全文
posted @ 2012-10-23 00:21 ETCOW 阅读(263) 评论(0) 推荐(0) 编辑
摘要: Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 public static List<BSTNode> UniqueBinarySearchTreeII(int n) 2 { 3 return UniqueBinarySearchT... 阅读全文
posted @ 2012-10-22 23:56 ETCOW 阅读(343) 评论(0) 推荐(0) 编辑
摘要: Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's.1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \2 1 2 3 1 public static int UniqueBinarySearchTrees(int n) 2 ... 阅读全文
posted @ 2012-10-22 23:20 ETCOW 阅读(283) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are 阅读全文
posted @ 2012-10-22 22:48 ETCOW 阅读(1923) 评论(0) 推荐(0) 编辑
摘要: 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 raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. 1 public static int TrappingRainWater(int[] A) 2 { 3 if (A.Length ... 阅读全文
posted @ 2012-10-22 22:21 ETCOW 阅读(240) 评论(0) 推荐(0) 编辑
摘要: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each 阅读全文
posted @ 2012-10-22 21:30 ETCOW 阅读(314) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. 1 public static 阅读全文
posted @ 2012-10-19 00:55 ETCOW 阅读(301) 评论(0) 推荐(0) 编辑
摘要: Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution. 1 public static void SudokuSolver(List<List<char>> board) 2 { 3 solver(board); 4 } 5 6 ... 阅读全文
posted @ 2012-10-19 00:07 ETCOW 阅读(401) 评论(0) 推荐(0) 编辑
摘要: You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening characters.For example, given:S: "barfoothefoobarman"L: ["foo", &q 阅读全文
posted @ 2012-10-18 23:56 ETCOW 阅读(491) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 10 下一页