2013年11月23日

Word Search

摘要: 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 "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.For example,Givenboard=[ [&q 阅读全文

posted @ 2013-11-23 22:58 waruzhi 阅读(180) 评论(0) 推荐(0) 编辑

Largest Rectangle in Histogram

摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文

posted @ 2013-11-23 17:23 waruzhi 阅读(180) 评论(0) 推荐(0) 编辑

Binary Tree Maximum Path Sum

摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.思路:递归调用函数。用函数comput计算从子树到根节点传递到根节点的父节点的值,然后用一个result记录在递归过程中求得的最大值。代码: 1 int max(int a, int b){ 2 if(a > b) 3 ... 阅读全文

posted @ 2013-11-23 13:38 waruzhi 阅读(145) 评论(0) 推荐(0) 编辑

Scramble String

摘要: Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf no... 阅读全文

posted @ 2013-11-23 10:51 waruzhi 阅读(216) 评论(0) 推荐(0) 编辑

导航