自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

yxccc的博客

欢迎来到我的博客

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

原创 LeetCoden 62. Unique Paths

62. Unique Paths递归解法超时,需要用动态规划动态规划解法 int uniquePaths(int m, int n) { if (m <= 0 || n <= 0) { return -1; } vector<vector<int>> res...

2018-06-25 00:15:08 237

原创 LeetCode 55. Jump Game

55. Jump Game水平有限,这题没有意识到是贪心的题,用递归和动态规划分别写了一遍。前者报超时,后者报内存限制。正确代码 bool canJump(vector<int>& nums) { if (nums.empty()) { return false; } // tan...

2018-06-23 21:26:54 296

原创 LeetCode 31. Next Permutation

31. Next Permutation这题不会做。。。 找全排列的下一个序列 最笨的方法是把全排列求出来,然后排个序,再得出下一个全排列。 但是空间不允许。这题也提供了一个直接找全排列下一个序列的方法 1.从后往前遍历数组,找出非递增的那个下标x 2.如果找不到,就是全排列的第一个。 3.找到后,与A数替换 A数是指(x + 1)–>nums.end()这段下标中,比...

2018-06-11 21:09:46 168

原创 LeetCode 292. Nim Game

292. Nim Game感觉这题还是很有意义的。让我意识到,算法题,其实核心还是数学思想。 有时候做算法题,还需要有抽象能力,转化能力。解法理解: 题意理解到,只要最终剩下4个,而且轮到对面先抽的轮次,那么等对方抽完,自己再抽剩下的,就赢了。 所以只要第一次把4的余数数量石头抽走,接下来,对方无论抽几个,我们就补几个凑成4。这样就保证了在最终的轮次会剩下4个,而且是对方先抽。...

2018-06-11 16:13:05 150

原创 LeetCode 257. Binary Tree Paths

257. Binary Tree Paths1.这道题,一开始使用find_last_of的时候,想要匹配 ‘-‘,但是val可以是负数,所以匹配错误。 2.整型转化为字符串的方法:利用stringstreamstringstream ss;ss << root->val;string rval = ss.str();class BinaryTreePaths ...

2018-06-11 11:26:52 182

原创 LeetCode 290. Word Pattern

290. Word Patternclass WordPattern {public: bool wordPattern(string pattern, string str) { if (pattern.empty() && str.empty()) { return true; } ...

2018-06-11 10:32:07 163

原创 LeetCode 205. Isomorphic Strings

205. Isomorphic Strings题目要求的是双向关系,一开始理解错了class IsIsomorphic {public: bool isIsomorphic(string s, string t) { if (s.size() != t.size()) { return false; }...

2018-06-10 21:42:47 124

原创 LeetCode 204. Count Primes

204. Count Primes主要是判断整数是否为质数,判断有如下三种,效率依次提高 bool isPrimes(int n) { bool bIsPrimes = true; for (int i = 2; i <= n; i++) { if (n % i == 0) ...

2018-06-10 17:46:17 179

原创 LeetCode 190. Reverse Bits

190. Reverse Bits二进制操作,一直是自己比较薄弱的地方。 解法一:对每个二进制位进行操作class ReverseBits {public: uint32_t reverseBits(uint32_t n) { uint32_t movement = n; uint32_t res = 0; int mask ...

2018-06-10 17:10:42 151

原创 LeetCode 172. Factorial Trailing Zeroes

172. Factorial Trailing Zeroes主要看5的个数就可以了。class TrailingZeroes {public: int trailingZeroes(int n) { if (n < 5) { return 0; } int count = 0; ...

2018-06-10 11:50:16 123

原创 LeetCode 168. Excel Sheet Column Title

168. Excel Sheet Column Title这题。。做了好久。脑子没转过来 1.以为是27进制,不知道怎么想的。。。 2.进制从0开始和从1开始。。。class ConvertToTitle {public: string convertToTitle(int n) { if (n < 1) { ...

2018-06-10 11:02:58 109

原创 LeetCode 122. Best Time to Buy and Sell Stock II

122. Best Time to Buy and Sell Stock IIclass MaxProfit {public: int maxProfit(vector<int>& prices) { if (prices.empty()) { return 0; } in...

2018-06-07 19:27:17 127

原创 Leetcode 112. Path Sum

112. Path Sum1.有点回溯的感觉,试完左树试右树。 2.注意叶子节点的判断条件 3.root=NULL,sum=0时也要返回false。class HasPathSum {public: bool hasPathSum(TreeNode* root, int sum) { if (root == NULL) { ...

2018-06-07 17:38:39 129

原创 LeetCode 111. Minimum Depth of Binary Tree

111. Minimum Depth of Binary Tree1.条件不能是root == NULL,而是判断叶子结点的条件。class MinDepth {public: int minDepth(TreeNode* root) { if (root == NULL) { return 0; } ...

2018-06-07 17:11:44 184

原创 Leetcode 110. Balanced Binary Tree

110. Balanced Binary Tree1.返回bool是为了返回判断的结果,判断当前的结点是否平衡 2.depth是为了记录高度class IsBalanced {public: bool isBalanced(TreeNode* root) { if (root == NULL) { return true;...

2018-06-07 16:48:10 142

原创 LeetCode 107.Binary Tree Level Order Traversal ii

107.Binary Tree Level Order Traversal ii拆分任务: 1.层次遍历 2.翻转vectorclass LevelOrderBottom {public: vector<vector<int>> levelOrderBottom(TreeNode* root) { if (root == NULL) ...

2018-06-05 16:55:55 178

原创 Leetcode 67.AddBinary

67.AddBinary跟66.Plus One 差不多,我还是先把他翻转过来。 因为有可能两个字符串长度不一样。短的字符串如果超出长度,循环时一直加0就好了。class AddBinary {public: string addBinary(string a, string b) { reverse(a.begin(), a.end()); ...

2018-06-05 13:18:16 133

原创 Leetcode 66.Plus One

66.Plus One我采用的方法是先把整个vector翻转,再顺序加。最后再重新翻转回来。class PlusOne {public: vector<int> plusOne(vector<int>& digits) { vector<int> tmpDig = digits; reverse(tm...

2018-06-05 12:30:25 146

原创 Leetcode 38.Count and Say

38.Count and Say 这题理解了题意就会比较好做。 1 11 21 1211 111221 规定第一项是 1 2时,读第一项,就是 1个1 3时,读第二项,就是 2个1 4时,读第三项,就是 1个2,1个1 …要把相同数字的归纳为数量表示出来。class CountAndSay {public: string coun...

2018-06-05 12:08:49 126

原创 leetcode 35.Search Insert Position

考查二分查找class SearchInsert {public: int searchInsert(vector<int>& nums, int target) { if (nums.empty()) { return 0; } int nLeft = 0; ...

2018-06-05 11:39:55 89

空空如也

空空如也

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

TA关注的人

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