上一页 1 2 3 4 5 6 7 8 ··· 17 下一页

2013年11月26日

Word Break

摘要: Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For example, givens="leetcode",dict=["leet", "code"].Return true because"leetcode"can be segmented as"leet code&quo 阅读全文

posted @ 2013-11-26 21:30 waruzhi 阅读(187) 评论(0) 推荐(0) 编辑

Longest Valid Parentheses

摘要: Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example is")()())", where the longest 阅读全文

posted @ 2013-11-26 20:17 waruzhi 阅读(167) 评论(0) 推荐(0) 编辑

Multiply Strings

摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.思路:大整数乘法,转换成大整数加法来算。代码: 1 string add(string num1, string num2){ 2 int l1 = num1.length(), l2 = num2.length(); 3 if(l1 > l2) 4... 阅读全文

posted @ 2013-11-26 13:17 waruzhi 阅读(274) 评论(0) 推荐(0) 编辑

Sudoku Solver

摘要: 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 @ 2013-11-26 11:01 waruzhi 阅读(156) 评论(0) 推荐(0) 编辑

Simplify Path

摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"Corner Cases:Did you consider the case wherepath="/../"?In this case, you should return"/".Another corner ca 阅读全文

posted @ 2013-11-26 00:02 waruzhi 阅读(206) 评论(0) 推荐(0) 编辑

2013年11月25日

Regular Expression Matching

摘要: Implement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(const char 阅读全文

posted @ 2013-11-25 17:04 waruzhi 阅读(165) 评论(0) 推荐(0) 编辑

Maximal Rectangle

摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:该题可以看作Largest Rectangle in Histogram的变形,对于每行,求出一个height数组,然后求出可以得到的最大值。参考资料:http://www.cnblogs.com/lichen782/p/leetcode_maximal_rectangle.html代码: 1 int maxRectangleInHistog 阅读全文

posted @ 2013-11-25 12:34 waruzhi 阅读(222) 评论(0) 推荐(0) 编辑

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) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 17 下一页

导航