摘要: 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.思路:第一种按照DFS搜索 阅读全文
posted @ 2013-06-11 23:29 一只会思考的猪 阅读(324) 评论(0) 推荐(0) 编辑
摘要: 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"] ] 1 class Solution { 2 public: 3 vector<ve 阅读全文
posted @ 2013-06-11 20:03 一只会思考的猪 阅读(227) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: bool partition_s(string s){ if (s.empty()){ return palin_m; } for(size_t i = 0; i < s.size(); i++){ palin_v.push_back(s.substr(i,1)); } palin_m.push_back(palin_v); vector<string> temp; while(1){... 阅读全文
posted @ 2013-06-11 16:33 一只会思考的猪 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 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?思路:递归和非递归的版本都应该会,非递归的版本需要使用到stack,不是O(1)的空间。而O(1)的空间是用了Morris的方法,和Threading结合起来,第一遍先进行中序Th... 阅读全文
posted @ 2013-06-11 16:27 一只会思考的猪 阅读(297) 评论(0) 推荐(0) 编辑
摘要: A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it cou 阅读全文
posted @ 2013-06-11 12:45 一只会思考的猪 阅读(149) 评论(0) 推荐(0) 编辑