自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(117)
  • 资源 (1)
  • 收藏
  • 关注

原创 真实面试题-消消乐连续三个或者三个以上字符消除

题目如:abbbaac消除结果是c因为leetcode也没有刷题链接,所以自己写了几个测试用例通过了一下,以下是代码:string xiaoxiaole(string s){ if(s.length()<=2) return s; stack<char> save; save.push(s[0]); int count=1; int i=1; string res = "";

2020-10-12 00:11:31 1893 1

原创 leetcode#416 分割等和子集

判断是否能把数字分成相等的两部分,先求和sum,如果sum不是2的倍数那么返回false,然后就变成,搜索是否存在一堆数 求和为sum/2,一开始想用递归:超时了动态规划算法:声明一个大小为sum/2+1的数组,dp[0]=true,然后两层循环:for(int num:nums){ for(int j=sum/2;j>=num;j--){ dp[j] = dp[j] || dp[j-num];//用当前元素和不用当前元素,哪一种情况为true,最终就为true...

2020-10-11 18:06:24 170

原创 leetcode#347-堆排序练习

vector<int> topKFrequent(vector<int>& nums, int k){ unordered_map<int,int> map; for(int i=0;i<nums.size();i++){ map[nums[i]]++; } priority_queue<pair<int,int...

2020-09-27 10:27:45 210

原创 LRU缓存-实现哈希链表结合

class LRUCache {private: int cap; list<pair<int ,int>> cache; unordered_map<int,list<pair<int,int>>::iterator> map;public: LRUCache(int capacity) { cap = capacity; } int get(int key) { .

2020-09-26 18:18:39 140

原创 216. 组合总和 III

class Solution {public: vector<vector<int>> all; vector<vector<int>> combinationSum3(int k, int n) { vector<int> one; for(int i=1;i<=9-k+1;i++){ com(i,k,n,one);//循环,从i出发作为第一个数去寻找后面的k-1.

2020-09-24 23:10:29 78

原创 220-重复元素3

class Solution {public: bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) { if (nums.empty()) return false; set<long> st; for (int i = 0; i < nums.size(); ++i) { .

2020-09-24 22:43:29 85

原创 数组-leetcode#128-最长连续序列

class Solution {public: int longestConsecutive(vector<int>& nums) { if(nums.size()==0) return 0; sort(nums.begin(),nums.end()); int max_len=1; int cur_len=1; for(int i=1;i<nums.size();i++){ .

2020-09-13 18:55:54 97

原创 leetcode#92-反转链表2

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* reverseBetween(ListNode* head, int m, int n) { if.

2020-09-13 16:42:51 86

原创 leetcode-除自身以外数组的乘积

class Solution {public: vector<int> productExceptSelf(vector<int>& nums) { vector<int> res(nums.size(),0); if(nums.size()<=1) return res; vector<int> go(nums.size(),0); vector<int> .

2020-09-12 20:29:28 79

原创 leetcode-回文链表

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: bool isPalindrome(ListNode* head) { if(head==NULL||head-&gt.

2020-09-12 19:41:29 68

原创 236. 二叉树的最近公共祖先

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

2020-09-12 19:09:55 85

原创 leetcode-和为k的子数组

class Solution {public: int subarraySum(vector<int>& nums, int k) { if(nums.size()<=0) return 0; int res=0; unordered_map<int,int> map; map[0]=1; int sum=0; for(int i=0;i<nums.size.

2020-09-12 18:47:16 125

原创 leetcode#125-数组中最大的k个数

class Solution {public: int findKthLargest(vector<int>& nums, int k) { if(nums.size()<=0||nums.size()<k) return -1; int res = quick(nums,0,nums.size()-1,nums.size()-k); return res; } int quick(vector&.

2020-09-12 13:20:42 289

原创 汉诺塔问题-递归

class Solution {public: void hanota(vector<int>& A, vector<int>& B, vector<int>& C) { if(A.size()<=0) return; int n=A.size(); move(n,A,B,C); return; } void move(int n,vector<.

2020-09-05 19:23:39 143

原创 数组-leetcode#31-下一个排列

class Solution {public: void nextPermutation(vector<int>& nums) { if(nums.empty()) return; int i=nums.size()-2; while(i>=0){ if(nums[i]<nums[i+1]) break; i--; } if(i>=.

2020-09-03 14:25:39 85

原创 数组-leetcode#27-原地移出元素

class Solution {public: int removeElement(vector<int>& nums, int val) { if(nums.empty()||nums.size()==0) return 0; int i=0;//i之前都排好了, for(int j=0;j<nums.size();j++){//移动j,把不等于val的元素放到i中,i++ if(nums[j]!=val){ .

2020-09-03 14:06:32 76

原创 leetcode#26-删除排序数组中的重复项

class Solution {public: int removeDuplicates(vector<int>& nums) { if(nums.empty()||nums.size()==0) return 0; int i=0; int j=0; while(i<nums.size()){ if(nums[i]==nums[j]) i++;//重复元素跳过 else{ .

2020-09-03 14:01:58 84

原创 leetcode#20-有效的括号

class Solution {public: bool isValid(string s) { if(s.length()<=0) return true; stack<char> save; if(s[0]=='('||s[0]=='['||s[0]=='{') save.push(s[0]); else return false; int i=1; while(i<s.length()){ i.

2020-09-03 12:36:11 86

原创 leetcode#144-二叉树的前序遍历

class Solution {public: vector<int> preorderTraversal(TreeNode* root) { vector<int> res; if(root==NULL) return res; digui(res,root); return res; } void digui(vector<int> & res,TreeNode *.

2020-08-29 21:51:05 91

原创 leetcode#138-复杂链表的复制

class Solution {public: Node* copyRandomList(Node* head) { if(head==NULL) return head; Node * p=head; //第一阶段,开辟空间,复制节点 while(p){ Node * tmp=new Node(p->val); tmp->next = p->next; .

2020-08-29 21:08:19 109

原创 leetcode#131-分割回文串

class Solution {public: vector<vector<string>> res; vector<vector<string>> partition(string s) { if(s.length()<=0) return res; vector<string> path; back(s,path,0);//从第0个位置开始,一路遍历到最后一个字符 return res;.

2020-08-29 18:51:20 95

原创 leetcode#130-被围绕的区域

class Solution {public: void solve(vector<vector<char>>& board) { if(board.size()<=0) return; int m = board.size();//行 int n = board[0].size();//列 for(int i=0;i<n;i++){ dfs(board,0,i);.

2020-08-29 16:20:38 98

原创 leetcode#129-求根到叶子节点之和

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector<int> res; i..

2020-08-29 15:35:18 98

原创 leetcode#127-字符串的最短转换序列

class Solution {public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { unordered_set<string> dict(wordList.begin(), wordList.end());//把字典中的字符变成hash_set加速查找 unordered_map<string, int&g.

2020-08-29 15:08:50 353

原创 链表排序-leetcode#148

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* sortList(ListNode* head) { if(!head||!head->ne.

2020-08-29 14:01:23 66

原创 youtobe推荐算法论文理解

主要看的是知乎上的那一篇,https://zhuanlan.zhihu.com/p/114703091一、背景介绍作为【推荐系统系列文章】的第一讲,我们将以YouTube在2016年发表的论文《Deep Neural Networks for YouTube Recommendations》为背景进行YouTube的深度神经网络推荐模型的介绍。在此这之前YouTube还有三篇介绍YouTube视频推荐的论文,如果将这四篇串在一起,也就组成了YouTube推荐系统不断发展改进的一个缩影。200

2020-08-27 19:26:22 1152

原创 leetcode#147-链表的插入排序

class Solution {public: ListNode* insertionSortList(ListNode* head) { if(head==NULL || head->next==NULL) return head; ListNode * dummy=new ListNode(INT_MIN); dummy->next = head; ListNode * pre = dummy; L.

2020-08-25 00:11:11 79

原创 leetcode#125-验证回文串

class Solution {public: bool isPalindrome(string s) { if(s.length()<=1) return true; int begin = 0; int end = s.length()-1; while(begin<end){ while(begin<end && !((s[begin]>='a' &&am.

2020-08-21 09:55:54 74

原创 leetcode#143-重排链表

class Solution {public: void reorderList(ListNode* head) { if(head==NULL) return; int n=0; ListNode * p = head; stack<ListNode *> s; while(p!=NULL){ s.push(p); p = p->next; n++; } //n.

2020-08-21 01:10:01 78

原创 leetcode#57-插入区间

class Solution {public: vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) { vector<vector<int>> res; if(newInterval.size()<=0) return intervals;.

2020-08-20 23:57:06 118

原创 leetcode#61-旋转链表

ListNode* rotateRight(ListNode* head, int k) { if(k<=0||head==NULL) return head; int n=0; ListNode * p = head; while(p!=NULL){ n++; p = p->next; } k = k%n; if(k==0) retu.

2020-08-19 20:26:35 82

原创 矩阵-单词搜索

class Solution {public: bool exist(vector<vector<char>>& board, string word) { if(board.size()<=0) return false; int m = board.size()-1; int n = board[0].size()-1; vector<vector<bool>> vis.

2020-08-19 17:41:00 196

原创 解码序列-真实面试题

vector<string> numDecodingsList(string s) { vector<string> dp; vector<string> dp_pre;//一开始为空,等到for执行1次就有了 if(s.length()<=0) return dp; if(s[0]-'0'>=1 && s[0]-'0'<=26){ dp.push_.

2020-08-19 11:36:57 101

原创 数组&排序-leetcode#56-合并区间

class Solution {public: vector<vector<int>> merge(vector<vector<int>>& intervals) { vector<vector<int>> res; if(intervals.size()<=0) return res; sort(intervals.begin(),intervals.end().

2020-08-17 00:11:16 114

原创 矩阵-leetcode#54-螺旋打印矩阵

class Solution {public: vector<int> spiralOrder(vector<vector<int>>& matrix) { vector<int> res; if(matrix.size()<=0) return res; int m = matrix.size()-1; int n = matrix[0].size()-1; .

2020-08-16 22:52:11 131

原创 MATH-leetcode#50-次幂计算-使用二分法

class Solution {public: double myPow(double x, int n) {//写一个递归函数,每次n/2次方,再平方, return half(x,n); } double half(double x,int n){ if(n==0) return 1.0; double half_n = half(x,abs(n)/2); half_n = n%2==0?half_n*half_.

2020-08-16 22:26:43 181

原创 数组-leetcode#34-二分查找确定左右边界

class Solution {public: vector<int> searchRange(vector<int>& nums, int target) { vector<int> res; if(nums.size()<=0) {res.push_back(-1);res.push_back(-1);return res;} int left = leftsearch(nums,targ.

2020-08-16 21:51:59 417

原创 数组&二分查找-leetcode#33-搜索旋转排序数组

class Solution {public: int search(vector<int>& nums, int target) { if(nums.size()<=0) return -1; int index=0; while(index<nums.size()-1){ if(nums[index+1]<nums[index]) break; in.

2020-08-15 20:06:16 102

原创 链表-leetcode#24-链表中节点两两交换

class Solution {public: ListNode* swapPairs(ListNode* head) { if(head==NULL||head->next==NULL) return head; ListNode * p1=head; ListNode * p2=head->next; ListNode * newhead = p2; ListNode * pre = NULL; .

2020-08-15 18:51:12 139

原创 链表分治结合-leetcode#23-合并k个链表

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next.

2020-08-15 18:07:53 104

数据结构课程设计红黑树源码

结对靠谱,本人经过验收的,适合初学者参考。

2014-05-09

空空如也

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

TA关注的人

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