
LeetCode
文章平均质量分 71
寻MEa
你要的明天,定会如约而至
展开
-
链表复制
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list. struct RandomListNode { i原创 2017-06-17 23:50:54 · 327 阅读 · 0 评论 -
LeetCode maximum path num
题目描述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 3原创 2017-07-06 16:51:44 · 199 阅读 · 0 评论 -
LeetCode word latter
题目描述Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start toend, such that:Only one letter can be changed at a timeEach inte原创 2017-07-06 16:50:12 · 319 阅读 · 0 评论 -
leetcode 字符串枚举
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s ="aab",Return [ ["aa","b原创 2017-07-06 16:48:38 · 239 阅读 · 0 评论 -
剑指offer值路径和查找
好久不用Java来写了,花了好久才accept题目描述输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。public class TreeNode { int val = 0; TreeNode left = null; TreeNode right =原创 2017-07-05 00:07:46 · 176 阅读 · 0 评论 -
二叉搜索树的性质
期末爆炸,昨晚作业来写一道题~~~题目描述输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。public class Solution { public boolean VerifySquenceOfBST(int [] sequence) {原创 2017-07-04 23:24:47 · 552 阅读 · 0 评论 -
Word_ladder
题目链接参考了大神的代码#include #include class Solution {public:void gen_path(unordered_map>& father, vector& path, string start, string word,vector>& ret){path.push_back(word);if (start == w原创 2017-06-20 22:42:34 · 190 阅读 · 0 评论 -
pat 中求解最长回文串的长度
本以为暴力枚举会超时,但竟然过了。。。#include #include #include int longestPalindrome(string s) {int left = 0, right = s.length() - 1;//为奇数时int len1 = 0;int len2 = 0;int start1 = left;//标记起始点int sta原创 2017-06-20 22:26:38 · 232 阅读 · 0 评论 -
scramble string (使用动态规划和递归做)
点击打开链接class Solution {public:bool solve(string s1, string s2, int left1, int right1, int left2)//串的位置{int dist = right1 - left1;if (dist == 1){return s1[left1] == s2[left2];}int la原创 2017-06-20 22:01:10 · 410 阅读 · 0 评论 -
LeetCode decode ways
点击打开链接class Solution {public: bool isdigit(char c){return c >= '0'&&c }int numDecodings(string s) {int dp[1000] = { 1 };//dp[i]表示前i个字符的方 if (s.length() == 0 || s[0] == '0')原创 2017-06-20 21:58:22 · 198 阅读 · 0 评论 -
LeetCode 重建BST
点击打开链接 struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} };class Solution {public: vector原创 2017-06-20 21:54:48 · 343 阅读 · 0 评论 -
LeetCode动态规划
题目链接Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 ="aabcc",s2 ="dbbca",When s3 ="aadbbcbcac", return true.When s3 ="aadbbbac原创 2017-06-20 21:52:31 · 205 阅读 · 0 评论 -
LeetCode二叉树的层序遍历的输出
题目链接 struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };class Solution {public: vector原创 2017-06-20 21:49:51 · 749 阅读 · 0 评论 -
LeetCode二叉树的恢复和重建(前序和中序)
点击打开链接 struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };class Solution {public: TreeN原创 2017-06-20 21:47:01 · 307 阅读 · 0 评论 -
leetcode 八皇后问题
题目链接class Solution {public:int a[100];bool issuit(int a[], int n, int row, int col)//判断是否适合放置{for (int i = 0; i {if (abs(a[i] - col) == abs(row - i) || col == a[i])return false;}原创 2017-06-20 21:43:53 · 670 阅读 · 0 评论 -
pat stack模拟,老超时wa......
#include #include #include #include #include using namespace std;class st{private:vector vec;public:st(){};~st(){};void pop(){if (vec.size() == 0){printf("%s\n", "Inv原创 2017-06-18 22:47:30 · 226 阅读 · 0 评论 -
LeetCode算法搜索
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原创 2017-06-18 00:13:03 · 192 阅读 · 0 评论 -
leetcode
题目描述Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may on原创 2017-07-06 16:53:37 · 219 阅读 · 0 评论