自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

vision的博客

读书笔记

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

原创 LeetCode 11. 盛最多水的容器

11. 盛最多水的容器 思路:双指针,放弃低的那边 class Solution { public: int maxArea(vector<int>& height) { int n=height.size(); int left=0, right=n-1, res=0; while(left<right){ ...

2020-04-18 09:48:37 120

原创 LeetCode 55. 跳跃游戏

55. 跳跃游戏 思路:贪心 class Solution { public: bool canJump(vector<int>& nums) { int len = nums.size(); if (len <= 1) return true; int maxDis = nums[0]; ...

2020-04-17 08:47:23 96

原创 LeetCode 56. 合并区间

56. 合并区间 思路:排序 class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { sort(intervals.begin(), intervals.end(), cmp); vector&l...

2020-04-16 13:55:22 112

原创 LeetCode 542. 01 矩阵

542. 01 矩阵 笔记 x*col+y这里卡了很久 class Solution { public: vector<vector<int>> updateMatrix(vector<vector<int>>& matrix) { row=matrix.size(), col=matrix[0].size();...

2020-04-15 10:53:14 112

原创 LeetCoed 5383. 给 N x 3 网格图涂色的方案数

5383. 给 N x 3 网格图涂色的方案数 分类:ABA, ABC各6种,每个ABA可与2ABC+3ABA结合, 每个ABC可与2ABC+2ABA结合 class Solution: def numOfWays(self, n: int) -> int: same, diff = 6, 6 # 代表初始时第一行两类各6种 for k in ...

2020-04-12 12:19:22 235

原创 LeetCode 5382. HTML 实体解析器

5382.HTML 实体解析器 class Solution: def entityParser(self, text: str) -> str: text = text.replace('&quot;', '"') text = text.replace('&apos;', "'") text = text.re...

2020-04-12 11:15:22 140

原创 LeetCode 5381. 查询带键的排列

5381.查询带键的排列 思路:链表 class Solution: def processQueries(self, queries: List[int], m: int) -> List[int]: res = [] P = [i for i in range(1, m+1)] for i, q in enumerate(q...

2020-04-12 11:06:46 154

原创 LeetCode 5380. 数组中的字符串匹配

5380.数组中的字符串匹配 python 字符串长度排序 class Solution: def stringMatching(self, words: List[str]) -> List[str]: res = [] words = sorted(words, key=lambda x: len(x)) for i, wo...

2020-04-12 10:44:59 153

原创 面试题 04.08. 首个共同祖先

面试题 04.08. 首个共同祖先 思路:要么一左一右,返回root,要么返回左,要么返回右 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) :...

2020-04-11 17:29:52 135

原创 面试题 04.06. 后继者

面试题 04.06. 后继者 思路:中序遍历,第一个大于p->val的就是答案。实在不会,用vector存中序遍历的TreeNode,一个个找。 class Solution { public: TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) { if(root==NULL) return NULL...

2020-04-11 17:20:17 182

原创 面试题 04.04. 检查平衡性

面试题 04.04. 检查平衡性 计算子树的高度差<2,一次遍历的话出现不平衡直接返回-1 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x)...

2020-04-10 22:19:20 260

原创 面试题 04.03. 特定深度节点链表

面试题 04.03. 特定深度节点链表 思路:层次遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL)...

2020-04-10 22:03:02 164

原创 面试题 04.02. 最小高度树

面试题 04.02. 最小高度树 思路:dfs,左子树和右子树 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(N...

2020-04-10 21:35:01 220

原创 LeetCode 151. 翻转字符串里的单词

151. 翻转字符串里的单词 class Solution: def reverseWords(self, s: str) -> str: l = s.split(' ') count = 0 for i in range(len(l)): if l[i]=='': count...

2020-04-10 10:05:45 84

原创 LeetCode 22. 括号生成

22. 括号生成 思路:dfs+剪枝, l,r代表左右括号数量。 class Solution { public: vector<string> generateParenthesis(int n) { vector<string> res; dfs(res, "", 0, 0, n); return res; ...

2020-04-09 10:49:56 69

原创 Microsoft Visual C++ 14.0 is required

pip install scikit-surprise出现安装错误 error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ 解决方法: 安装Microsoft Visual C...

2020-04-08 19:33:51 413

原创 面试题13. 机器人的运动范围

面试题13. 机器人的运动范围 思路:dfs+判断 class Solution { public: int movingCount(int m, int n, int k) { res = 0; dfs(0,0,m,n,k); return res; } private: int res; bool flag[...

2020-04-08 11:39:36 118

原创 LeetCode 5377. 将二进制表示减到 1 的步骤数

5377.将二进制表示减到 1 的步骤数 思路:先变成整数,在运算。C++变成整数会溢出,所以用pyhton,//代表整除 class Solution: def numSteps(self, s: str) -> int: length = len(s) num = int(s,2) res = 0 while...

2020-04-05 10:53:03 416

原创 LeetCode 5376. 非递增顺序的最小子序列

5376.非递增顺序的最小子序列 思路:先大到小排序,然后值相加,判断条件 class Solution { public: vector<int> minSubsequence(vector<int>& nums) { sort(nums.begin(), nums.end(), cmp); vector<in...

2020-04-05 10:38:01 175

原创 LeetCode 42. 接雨水

42. 接雨水 思路: 接水的值=min(左边最大,右边最大)-height[i] class Solution { public: //思路:ans += min(left, right)-height[i] int trap(vector<int>& height) { int size = height.size(); if...

2020-04-04 09:46:34 111

原创 LeetCode 289. 生命游戏

289. 生命游戏 思路:数每个格子周围Cell存活数 笔记:vector复制 vector<vector<int> > tmp(board); class Solution { public: void gameOfLife(vector<vector<int>>& board) { vector<ve...

2020-04-02 11:04:45 103

原创 LeetCode 1111. 有效括号的嵌套深度

1111. 有效括号的嵌套深度 思路:我们只需要把奇数层的(分配给A,偶数层的(分配给B即可 //'('时奇数为1,偶数为0 class Solution { public: vector<int> maxDepthAfterSplit(string seq) { vector<int> res; int d=...

2020-04-01 10:37:37 134

原创 LeetCode 20. 有效的括号

20. 有效的括号 思路:1.用栈,2.用left代表有多少个左边的符号 class Solution { public: bool isValid(string s) { stack<char> st; for(char ch: s){ if(st.size()==0) st.push(ch); ...

2020-04-01 09:24:54 74

空空如也

空空如也

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

TA关注的人

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