
剑指offer
端木亽
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
剑指offer(二)
6. 重建二叉树 递归构建二叉树 /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };...原创 2019-07-18 10:23:14 · 143 阅读 · 0 评论 -
剑指offer(十三)
61. 构建乘积数组 由于不能使用除法,使用数组C 表示 A[i] 左边的乘积,D表示 A[i] 右边的乘积,两者相乘即得结果。 class Solution { public: vector<int> multiply(const vector<int>& A) { if(A.size()<=1) return {}; ...原创 2019-08-14 14:03:09 · 179 阅读 · 0 评论 -
剑指offer(十)
46. 两个链表的第一个公共节点 栈的方法。 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindFirstCommonNode( ListNode* p...原创 2019-08-09 20:03:07 · 177 阅读 · 0 评论 -
剑指offer(十二)
56. 滑动窗口的最大值 这题我觉得最麻烦的是,size使用的 unsigned int的类型,导致后面有点麻烦,所以我直接转成int型了。 class Solution { public: vector<int> maxInWindows(const vector<int>& num, unsigned int size) { st...原创 2019-08-14 10:50:28 · 251 阅读 · 0 评论 -
剑指offer(八)
36. 数组中出现次数超过一半的数字 自己想的是类似于桶排序的方法,时间复杂度虽然是O(n),但是是用的空间换时间,不划算。 class Solution { public: int MoreThanHalfNum_Solution(vector<int> numbers) { int size=numbers.size(); if(size&l...原创 2019-08-06 20:14:13 · 111 阅读 · 0 评论 -
剑指offer(九)
41. 把数组排成最小的数 方法的本质是排序,但是排序标准改为在前面的做高位得到的数小;由于冒泡写起来简单就用了冒泡,就时间复杂度而言还是应该用快排。 class Solution { public: string PrintMinNumber(vector<int> numbers) { if(numbers.size()<=0) return "";...原创 2019-08-08 21:00:12 · 193 阅读 · 0 评论 -
剑指offer(七)
31. 二叉树中和为某一值的路径 class Solution { public: vector<vector<int> > FindPath(TreeNode* root,int expectNumber) { vector<vector<int> > result; vector<int> br...原创 2019-08-01 14:41:17 · 131 阅读 · 0 评论 -
剑指offer(四)
16. 删除链表中重复的节点 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; */ class Solution { public: ListNode* deleteDuplication(List...原创 2019-07-22 17:20:56 · 114 阅读 · 0 评论 -
剑指offer(六)
26. 顺时针打印矩阵 因为弄反了行列,所以因为溢出折腾了好一会。做之前感觉递归会更方便,现在还是觉得循环更简单些。 class Solution { public: void printM(vector<vector<int> > matrix,int rowbegin,int rowend,int colbegin,int colend,vector<in...原创 2019-07-25 11:00:08 · 159 阅读 · 0 评论 -
剑指offer(三)
11. 旋转数组的最小数字 二分法,书上说考的是二分法。。 class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { int size=rotateArray.size(); if(size==0) return 0; if(siz...原创 2019-07-19 19:50:18 · 132 阅读 · 0 评论 -
剑指offer(五)
21. 链表中环的入口节点 这是比较清晰的方式,但是面试时我应该想不出来这个规律,这也是看了别人的答案才知道这个规律的。 /* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; */ class Solution ...原创 2019-07-24 10:43:01 · 116 阅读 · 0 评论 -
剑指offer(一)
把字符串转换成整数 class Solution { public: int StrToInt(string str) { if(str.empty()) return 0; int nums=0, flag=1; if(str[0]=='-') flag=-1; else if(str[0]=='+') nums=0; ...原创 2019-07-16 14:28:49 · 171 阅读 · 0 评论 -
剑指offer(十一)
51.原创 2019-08-12 20:32:28 · 133 阅读 · 0 评论