自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

fly away!

你要的明天,定会如约而至

  • 博客(26)
  • 收藏
  • 关注

转载 快排的递归和非递归版

#include<iostream>#include<vector>#include<stack>#include<cstdlib>#include<algorithm>using namespace std; /**把数组分为两部分,轴pivot左边的部分都小于轴右边的部分**/template <typename Compara...

2018-04-28 12:25:01 351

原创 剑指offer 旋转数组的最小数字

题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。旋转之后的数组实际上可以划分成两个有序的子数组:前面子数组的大小都大于后面子数组中的

2017-08-12 21:33:33 190

原创 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 186

原创 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 173

原创 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 292

原创 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 200

原创 剑指offer值路径和查找

好久不用Java来写了,花了好久才accept题目描述输入一颗二叉树和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。public class TreeNode {    int val = 0;    TreeNode left = null;    TreeNode right =

2017-07-05 00:07:46 153

原创 二叉搜索树的性质

期末爆炸,昨晚作业来写一道题~~~题目描述输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。public class Solution {    public boolean VerifySquenceOfBST(int [] sequence) {       

2017-07-04 23:24:47 500

原创 PAT题目 有几个PAT(25)

题目链接有点动态规划的味道。#include int main(){char s[100];int p=0, pa=0, pat=0;scanf("%s", s);int len = strlen(s);for (int i = 0; i {switch (s[i]){case 'p':p += 1;break;case 'a':

2017-06-24 23:27:40 321

原创 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 167

原创 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 208

原创 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 372

原创 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 155

原创 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 309

原创 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 178

原创 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 701

原创 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 267

原创 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 633

原创 count the pat

counting the patint main(){int p=0, pa=0, pat = 0;char s[100000] = { 0 };scanf("%s", s);int i = 0;while (s[i]!=0){switch (s[i]){case 'P':p++;break;case 'A':pa += p;pa

2017-06-20 21:37:25 165

原创 pat 精度问题

点击打开链接老TLE,可以看出浮点运算的复杂程度远大于整数运算。怎么优化。。。int main(){float f1, f2;int dignum;scanf("%d", &dignum);scanf("%f %f", &f1, &f2);float t1 = f1, t2 = f2;int count1 = 0, count2 = 0;while (t

2017-06-20 13:06:09 258

原创 pat水题

题目链接int main(){char a[100], b[100];int a1, b1, c1, a2, b2, c2,a3,b3,c3;scanf("%d.%d.%d", &a1, &b1, &c1);scanf("%d.%d.%d", &a2, &b2, &c2);int ca1, ca2;//表示进位c3 = (c1 + c2) % 29;ca1 =

2017-06-19 22:39:31 140

原创 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 198

原创 pat水题

自以为对二进制有很深的理解,面对这种水题,切了好久。。。题目链接#include #include typedef long long  ll;bool compare(ll a, ll b, ll c)//防止大数相加溢出{if (a > 0 && b > 0){if (a > LLONG_MAX - b)return true;}if

2017-06-18 12:41:50 268

原创 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 154

原创 回文子串

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-06-18 00:08:00 196

原创 链表复制

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 285

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除