2013年11月26日

Binary Tree Preorder Traversal

摘要: Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Note:Recursive solution is trivial, could you do it iteratively?如果不能使用recursive 那么就只能使用stack来保存状态。 1 /** 2 * Definition for binary tree 3 * public clas... 阅读全文

posted @ 2013-11-26 13:05 Step-BY-Step 阅读(187) 评论(0) 推荐(0) 编辑

Linked List Cycle II

摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space? 1 public class Solution { 2 public ListNode detectCycle(ListNode head) { 3 // IMPORTANT: Please reset any member data you declared, as 4 ... 阅读全文

posted @ 2013-11-26 09:33 Step-BY-Step 阅读(134) 评论(0) 推荐(0) 编辑

Linked List Cycle

摘要: Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space? 1 public class Solution { 2 public boolean hasCycle(ListNode head) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be ... 阅读全文

posted @ 2013-11-26 09:30 Step-BY-Step 阅读(133) 评论(0) 推荐(0) 编辑

Palindrome Partitioning II

摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, givens="aab",Return1since the palindrome partitioning["aa","b"]could be produced using 1 cut.这个两个Dp, 一个是对那 阅读全文

posted @ 2013-11-26 09:23 Step-BY-Step 阅读(199) 评论(0) 推荐(0) 编辑

Palindrome Partitioning

摘要: Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]采用DP来做。为了不重复计算palindrome, 使用一个map 存储从[i,j]是否 阅读全文

posted @ 2013-11-26 07:29 Step-BY-Step 阅读(241) 评论(0) 推荐(0) 编辑

Surrounded Regions

摘要: Given a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X X X XX X X XX X X 阅读全文

posted @ 2013-11-26 07:02 Step-BY-Step 阅读(161) 评论(0) 推荐(0) 编辑

Best Time to Buy and Sell Stock III

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).和前两道题比起来的话, 阅读全文

posted @ 2013-11-26 03:21 Step-BY-Step 阅读(185) 评论(0) 推荐(0) 编辑

导航