上一页 1 2 3 4 5 6 ··· 11 下一页

2013年7月28日

摘要: Problem:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7return its zigzag level order traversal as:... 阅读全文
posted @ 2013-07-28 12:13 freeneng 阅读(185) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?Analysis:Basic tree traversal problems. Recursive solution is just to proper arran... 阅读全文
posted @ 2013-07-28 11:48 freeneng 阅读(142) 评论(0) 推荐(0) 编辑
摘要: Problem:Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a characterAnalysis:This is the classic dynamic p 阅读全文
posted @ 2013-07-28 11:00 freeneng 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Problem:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.Analysis:This is the extension of the former N-Queens problem. If we use the code before directly, there will be TLE problem. After checking the code, we find the isVali 阅读全文
posted @ 2013-07-28 08:41 freeneng 阅读(248) 评论(0) 推荐(0) 编辑
摘要: Problem:Then-queens puzzle is the problem of placingnqueens on ann�nchessboard such that no two queens attack each other.Given an integern, return all distinct solutions to then-queens puzzle.Each solution contains a distinct board configuration of then-queens' placement, where'Q'and' 阅读全文
posted @ 2013-07-28 07:16 freeneng 阅读(225) 评论(0) 推荐(0) 编辑

2013年7月27日

摘要: Problem: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.Analysis:It's the big number simulation problem. Recall the process how we compute the multiplication manually. Multiply the tow numb 阅读全文
posted @ 2013-07-27 08:02 freeneng 阅读(226) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is not found in the array, return[-1, -1].For example,Given[5, 7, 7, 8, 8, 10]and target value 8,return[3, 4].A 阅读全文
posted @ 2013-07-27 06:18 freeneng 阅读(182) 评论(0) 推荐(0) 编辑

2013年7月26日

摘要: Problem:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array.Analysis:The problem is 阅读全文
posted @ 2013-07-26 12:56 freeneng 阅读(159) 评论(0) 推荐(0) 编辑

2013年7月25日

摘要: Problem:Divide two integers without using multiplication, division and mod operator.Analysis:I think the problem wants us to use binary search to find the answer instead of simply using some arithmetic operations. So the binary search version comes first. When dealing with it, pay attention to the e 阅读全文
posted @ 2013-07-25 08:27 freeneng 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Example 2:Given[1,2],[3,5], 阅读全文
posted @ 2013-07-25 06:32 freeneng 阅读(183) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 11 下一页

导航