自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(21)
  • 收藏
  • 关注

原创 Leetcode 125. 验证回文串

class Solution {public: bool isPalindrome(string s) { int l=0,r=(int)s.size()-1; while(l<r){ if(!isalnum(s[l])) ++l; else if(!isalnum(s[r])) --r; ...

2018-06-11 10:43:07 468

原创 Leetcode 124. 二叉树中的最大路径和

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-11 10:34:44 651

原创 Leetcode 123. 买卖股票的最佳时机 III

一个从左往右算当前的最大利润【一笔交易】 一个从右往左算当前的最大利润【一笔交易】{按Leetcode121算} 然后答案就是一笔交易最大利润,以任意点为分割点的左右各1笔交易的和中最大的一个class Solution {public: int maxProfit(vector<int>& prices) { if(prices.empty(...

2018-06-10 11:09:05 712

原创 Leetcode 122. 买卖股票的最佳时机 II

若P[k]>=P[k-1]那么在k-1时选择不卖出,否则卖出class Solution {public: int maxProfit(vector<int>& prices) { prices.push_back(0); int m=prices[0],ans=0; for(int k=1;k<pric...

2018-06-10 10:47:48 910

原创 Leetcode 121. 买卖股票的最佳时机

class Solution {public: int maxProfit(vector<int>& prices) { int m=0x3f3f3f3f,ans=0;//当前最小值 for(int k=0;k<prices.size();++k) m=min(m,prices[k]),ans=max(an...

2018-06-10 10:40:03 126

原创 Leetcode 120. 三角形最小路径和

动态规划class Solution {public: int minimumTotal(vector<vector<int>>& triangle) { vector<int> dp(triangle.size(),0); for(int i=0;i<triangle.size();++i){ ...

2018-06-10 10:36:34 533

原创 Leetcode 119. 杨辉三角 II

C(n,0) C(n,1) C(n,2) ……C(n,n)class Solution {public: vector<int> getRow(int rowIndex) { vector<int> ans(1,1); for(int k=1;k<=rowIndex;++k) ans.push_back((long lon...

2018-06-06 21:24:44 478

原创 Leetcode 118. 杨辉三角

简单题class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>> ans; vector<int> t; while(numRows--){ ...

2018-06-06 21:18:43 380

原创 Leetcode 117. 填充同一层的兄弟节点 II

116的普遍情况/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), n...

2018-06-06 21:12:50 766

原创 Leetcode 116. 填充同一层的兄弟节点

每次递归的输入,第k层的起始结点【通过next访问第k层其他结点】/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), l...

2018-06-06 21:10:02 378

原创 Leetcode 115. 不同的子序列

class Solution {public: int numDistinct(string s, string t) { if (s.empty()) return 0; vector<int> dp(s.size(), 1); int pre, temp; for (int i = 0; i < t.s...

2018-06-05 21:59:30 719

原创 Leetcode 114. 二叉树展开为链表

先整成左子树的形式【右子结点在先序遍历中递归返回后还要遍历,不能覆盖】/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left...

2018-06-03 11:16:35 1015

原创 Leetcode 113. 路径总和 II

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-03 11:07:02 550

原创 Leetcode 112. 路径总和

递归/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */...

2018-06-03 10:56:24 215

原创 Leetcode 111. 二叉树的最小深度

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-02 10:06:05 438

原创 Leetcode 110. 平衡二叉树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-02 09:57:42 678

原创 Leetcode 109. 有序链表转换二叉搜索树

和108一样/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *//** * Definition for a binary tr...

2018-06-02 09:41:16 732

原创 Leetcode 108. 将有序数组转换为二叉搜索树

一种策略是构建完全二叉树/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {}...

2018-06-02 09:36:52 237

原创 Leetcode 107. 二叉树的层次遍历 II

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-02 09:20:39 427

原创 Leetcode 106. 从中序与后序遍历序列构造二叉树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-02 09:20:12 464

原创 Leetcode 105. 从前序与中序遍历序列构造二叉树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2018-06-02 09:19:40 388

空空如也

空空如也

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

TA关注的人

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