摘要: Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.方法一:最先想到的就是递归,注... 阅读全文
posted @ 2014-06-27 17:53 穆穆兔兔 阅读(162) 评论(0) 推荐(0) 编辑
摘要: Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文
posted @ 2014-06-27 14:03 穆穆兔兔 阅读(234) 评论(0) 推荐(0) 编辑
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, wh... 阅读全文
posted @ 2014-06-26 18:02 穆穆兔兔 阅读(189) 评论(0) 推荐(0) 编辑
摘要: Givennnon-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.Fo... 阅读全文
posted @ 2014-06-26 14:36 穆穆兔兔 阅读(187) 评论(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 on... 阅读全文
posted @ 2014-06-25 17:11 穆穆兔兔 阅读(169) 评论(0) 推荐(0) 编辑
摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with ... 阅读全文
posted @ 2014-06-25 16:45 穆穆兔兔 阅读(168) 评论(0) 推荐(0) 编辑
摘要: There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requi... 阅读全文
posted @ 2014-06-25 15:58 穆穆兔兔 阅读(175) 评论(0) 推荐(0) 编辑
摘要: The set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie... 阅读全文
posted @ 2014-06-24 17:54 穆穆兔兔 阅读(225) 评论(0) 推荐(0) 编辑
摘要: http://stackoverflow.com/questions/200384/constant-amortized-time分摊常量时间:Amortised time explained in simple terms:If you do an operation say a million ... 阅读全文
posted @ 2014-06-24 16:58 穆穆兔兔 阅读(1059) 评论(0) 推荐(1) 编辑
摘要: 当所给问题是从n个元素的集合S中找出满足某种性质的子集时,解空间为子集树。例如:0-1背包问题当所给问题是从n个元素的集合S中找出满足某种性质的排列时,解空间为排列树。例如:旅行售货员问题回溯法搜索子集树算法描述为:void backtrack(int t){ if(t>n) output... 阅读全文
posted @ 2014-06-24 11:29 穆穆兔兔 阅读(4531) 评论(0) 推荐(2) 编辑