自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

小堃哥的专栏

写博客:网址链接+名称:oj名+所用算法名称+该题注意事项和心得

  • 博客(58)
  • 资源 (1)
  • 收藏
  • 关注

原创 leetcode329+二维矩阵上的最长路径,DP加上DFS

https://leetcode.com/problems/longest-increasing-path-in-a-matrix/description/class Solution {public: int dfs(vector<vector<int>>& matrix, vector<vector<int>>& ...

2018-07-31 20:44:10 1461

原创 leetcode342+判断是否是4的幂,不用循环,用位运算

https://leetcode.com/problems/power-of-four/description/class Solution {public: bool isPowerOfFour(int num) { if(num&(num-1)) return false; else if(num&0x55555555) retu...

2018-07-30 11:57:40 263

原创 leetcode345+ 翻转元音字母,使用双指针

https://leetcode.com/problems/reverse-vowels-of-a-string/description/class Solution {public: bool isVowel(char c) { if( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || ...

2018-07-29 16:13:07 152

原创 leetcode350 + 求两个数组的交集,有重复,map累计计数

https://leetcode.com/problems/intersection-of-two-arrays-ii/description/class Solution {public: vector<int> intersect(vector<int>& nums1, vector<int>& nums2) { ...

2018-07-29 14:49:28 288

原创 leetcode349+ 求两个数组交集,不重复数字,hash

https://leetcode.com/problems/intersection-of-two-arrays/description/class Solution {public: vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { ...

2018-07-29 14:24:36 196

原创 leetcode315 + 二分,每个数字后面小的数个数

https://leetcode.com/problems/count-of-smaller-numbers-after-self/description/class Solution {public: vector<int> countSmaller(vector<int>& nums) { vector<int> t...

2018-07-29 00:10:59 257

原创 leetcode312+区间Dp,类似于堆石子,三层循环有规律的

https://leetcode.com/problems/burst-balloons/description/class Solution {public: int maxCoins(vector<int>& nums) { int n = nums.size(); nums.insert(nums.begin(), 1);...

2018-07-28 19:02:34 295

原创 leetcode + 不断增加数据,求中位数+二分

https://leetcode.com/problems/find-median-from-data-stream/description/class MedianFinder {public: vector<int> nums; /** initialize your data structure here. */ MedianFinder() {...

2018-07-28 00:07:20 391

原创 leetcode557+ reverse string+使用stack,注意最后一个string的空格问题

https://leetcode.com/problems/reverse-words-in-a-string-iii/description/class Solution {public: string reverseWords(string s) { stack<char> st; string str=""; for...

2018-07-27 19:58:34 134

原创 leetcode653+ TwoSum_BST+必定使用hash

https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}...

2018-07-27 13:32:52 158

原创 leetcode + first_bad_version+二分

https://leetcode.com/problems/first-bad-version/description/// Forward declaration of isBadVersion API.bool isBadVersion(int version);class Solution {public: int firstBadVersion(int n) { ...

2018-07-24 19:22:08 177

原创 leetcode+ Nim博弈,看是不是4的倍数

https://leetcode.com/problems/nim-game/description/class Solution {public: bool canWinNim(int n) { if(n%4==0) return false; return true; }}; 

2018-07-24 17:25:06 228

原创 leetcode290+ 字符和string匹配,双向hash

https://leetcode.com/problems/word-pattern/description/class Solution {public: bool wordPattern(string pattern, string str) { map<char,string> map1; map<string,char&gt...

2018-07-24 16:26:00 134

原创 leetcode173+设计题,就是BST返回下一个最小数,画个BST程序走一遍,就知道next在stack为何这样操作了

https://leetcode.com/problems/binary-search-tree-iterator/description/struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {...

2018-07-24 10:41:04 122

原创 leetcode72+ 最小编辑距离,DP二维数组上求

https://leetcode.com/problems/edit-distance/description/class Solution {public: int minDistance(string word1, string word2) { int len1 = word1.size(), len2 = word2.size(); vect...

2018-07-23 19:39:43 701

原创 leetcode + 移除数组中的0到末尾,双指针问题

https://leetcode.com/problems/move-zeroes/description/class Solution {public: void moveZeroes(vector<int>& nums) { if(nums.empty()) return; int fill = 0, cur = 0; ...

2018-07-23 11:47:05 156

原创 leetcode+从左到右每一个区间里的最大数,双向单调队列

https://leetcode.com/problems/sliding-window-maximum/description///双向单调队列class Solution {public: vector<int> maxSlidingWindow(vector<int>& nums, int k) { //双向队列是从大到小的 ...

2018-07-23 11:09:14 402

原创 leetcode+移除最少的括号到合理,BFS+hash记录visit

https://leetcode.com/problems/remove-invalid-parentheses/description/class Solution {public: bool isvalid(string t) { int cnt = 0; for(int i=0; i < t.size(); i++){ ...

2018-07-22 13:44:50 481

原创 leetcode + 一串数组里数字,找到0->n最开始不存在的数字,set进行hash

https://leetcode.com/problems/missing-number/description/class Solution {public: int missingNumber(vector<int>& nums) { set<int>st; for(int i=0; i<nums.size(...

2018-07-22 11:16:37 106

原创 leetcode+ 二叉树root->root的所有路径存储,递归

https://leetcode.com/problems/binary-tree-paths/description//** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tree...

2018-07-22 00:31:01 768

原创 leetcode+add_digits+直接循环到digits和是小于10

https://leetcode.com/problems/add-digits/description/class Solution {public: int addDigits(int num) { while (num>=10) { int sum =0; while (num>0) { ...

2018-07-21 23:04:50 105

原创 leetcode + 判断两字符串是不是同构子串。就是一串字符串,两种顺序排列。先sort然后判别

https://leetcode.com/problems/valid-anagram/description/class Solution {public: bool isAnagram(string s, string t) { sort(s.begin(), s.end()); sort(t.begin(), t.end()); ...

2018-07-20 10:45:32 351

原创 leetcode+ BST中两个节点的最近公共祖先,递归,要使用中序有序的属性

https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/description/struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(N...

2018-07-19 19:33:26 351

原创 leetcode+判断是否是2的幂,注意if判断

https://leetcode.com/problems/power-of-two/description/class Solution {public: bool isPowerOfTwo(int n) { if(n<=0 || n>2147483647)//2的幂最小是1 int最大为2147483647 return f...

2018-07-19 12:09:53 512

原创 leetcode+ 栈模拟队列,front_val记录队列首值

https://leetcode.com/problems/implement-queue-using-stacks/description/class MyQueue {public: /** Initialize your data structure here. */ stack<int> st, tmp; int front_val=0; ...

2018-07-18 11:40:11 126

原创 leetcode+ 队列模拟栈,pop使用双队列,topValue记录栈顶值

https://leetcode.com/problems/implement-stack-using-queues/description/class MyStack {public: queue<int> Q, tmp; int topValue; /** Initialize your data structure here. */ MyS...

2018-07-18 11:07:40 277

原创 leetcode+ 二叉树左右颠倒,递归

https://leetcode.com/problems/invert-binary-tree/description/struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};cla...

2018-07-18 10:21:37 443

原创 leetcode+ 乘法模拟,DFS

https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/class Solution {public: char Mp[10][5] = {"","","abc", "def", "ghi", "jkl", "mno", "pqrs&quot

2018-07-16 17:06:13 216

原创 leetcode+ 添加首部几个字母数,回文子串,KMP

点击打开链接class Solution {public: string shortestPalindrome(string s) { string r = s; reverse(r.begin(), r.end()); string t = s+'#'+r; vector<int> next(t.size(),...

2018-07-16 14:21:20 118

原创 leetcode+ 二叉树所有左子叶点sum,递归

点击打开链接class Solution {public: int sum =0; int sumOfLeftLeaves(TreeNode* root) { if (root == NULL) return 0; if (root->left) { if (root->left->left == NUL...

2018-07-15 17:04:24 347

原创 leetcode +判断两字符串是否同构,双向验证hash

点击打开链接class Solution {public: bool isIsomorphic(string s, string t) { if(s.size() != t.size()) return false; map<char, char> s2t, t2s; for(int i=0; i<s.size(); i+...

2018-07-15 13:03:01 422

原创 leetcode+判断小于n的素数数目,筛法

点击打开链接//筛法class Solution {public: int countPrimes(int n) { vector<bool> num(n+1, true); num[0] = false, num[1] = false; int res = 0, limit = sqrt(n); for(in...

2018-07-15 10:40:43 303

原创 leetcode+ happy_number, set类似hash

点击打开链接class Solution {public: set<int> st; int getSum(int n) { int sum = 0; while(n>=1){ sum += (n%10)*(n%10); n /= 10; } ...

2018-07-15 10:18:07 108

原创 leetcode+ 字符串中找出能匹配目标子串的最短区间

点击打开链接class Solution {public: string minWindow(string s, string t) { map<char, int> m; for(int i=0; i<t.size(); i++){ m[t[i]] +=1; } int cnt=0...

2018-07-14 20:40:16 1101

原创 leetcode +恢复二叉树

点击打开链接struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {}};class Solution {public: void helper(TreeNode* root, Tree...

2018-07-14 20:36:58 363

原创 leetcode+ s3是否是由s1和s2构成,Dp

点击打开链接//Dpclass Solution {public: bool isInterleave(string s1, string s2, string s3) { int len1 = s1.size(), len2 = s2.size(); if(s3.size() != len1+len2) return false; ve...

2018-07-14 20:34:03 381

原创 leetcode+ 子数组是否是k的倍数,Dp的思想

点击打开链接class Solution {public: bool checkSubarraySum(vector<int>& nums, int k) { int sz = nums.size(); vector<int> sum(nums.begin(), nums.end()); for(int le...

2018-07-14 20:31:56 854

原创 leetcode+ 括号匹配的最大长度

点击打开链接//需要借助变量l记录当前括号匹配的子串的左侧位置class Solution {public: int longestValidParentheses(string s) { int res =0, l=0; stack<int> st; for(int i=0; i<s.size(); i++){ ...

2018-07-14 20:24:19 674

原创 leetcode+scramble string,字符串上的Dp

点击打开链接 //Dpclass Solution {public: bool isScramble(string s1, string s2) { if(s1.size() != s2.size()) return false; if(s1==s2) return true; int n = s1.size(); vec...

2018-07-14 20:20:17 174

原创 leetcode+ 桶排序

点击打开链接//没看懂class Solution {public: int maximumGap(vector<int>& nums) { if(nums.empty()) return 0; int mx = INT_MIN, mn = INT_MAX, n=nums.size(); for(int d: nums...

2018-07-14 20:04:51 458

c语言版贪吃蛇

很好的一个源代码,相当不错

2014-01-24

空空如也

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

TA关注的人

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