随笔分类 - leetcode
leetcode之Palindrome Partitioning
摘要:方法一:DFS递归,判断每一个是否为回文数1,首先要有一个判断字符串是否是回文的函数。容易实现,字符串从两边同时往中间走,看字符是否相同;2,深度优先搜索思想对字符串进行遍历。得到结果。例如,s = "abacd"; 需要对“a”“ad”“aba”“abac”“abacd”进行深度优先搜索。深度搜索...
阅读全文
Letter Combinations of a Phone Number
摘要:思路很简单,就是通过map对应,随后通过递归调用,这里遇到了个问题就是开始用string &re ,然后往里传re+c是不可以的,本来想省点内存,结果不行,所以只能值传递了,后来才知道string竟然还有push_back()和pop_back(),服了。 1 class Solution { 2 ...
阅读全文
Leetcode Construct Binary Tree from Inorder and Postorder Traversal
摘要:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.常规方法,以中序为主,在中序...
阅读全文
leetcode Pow(doubule x,int n)
摘要:今天第一天开通博客,心情还是小激动的上代码:方法一:常规递归,x的n次方={xn/2*xn/2 //n为偶 xn/2*xn/2 *x //n为奇数 } 1 class Solution { 2 public: 3 bool isinvalid=false; /...
阅读全文
浙公网安备 33010602011771号