
算法
菜鸟numberone
这个作者很懒,什么都没留下…
展开
-
滑动窗口的最大值,矩阵中的路径,机器人的运动范围,剪绳子(剑指offer65-68)c++版本
#include <iostream>#include <vector>#include <deque>using namespace std;class Solution {public: //JZ65 滑动窗口的最大值 vector<int> maxInWindows(const vector<int>& num, unsigned int size); //JZ66 矩阵中的路径 bool hasPath(cha原创 2020-09-01 16:21:13 · 157 阅读 · 0 评论 -
序列化二叉树,二叉搜索树的第K个结点,数据流中的中位数(JZ61-63)C++版本)
#include <iostream>#include <string>#include <cstring>#include <vector>#include <functional>//less, greater#include <algorithm>using namespace std;struct TreeNode { int val; struct TreeNode *left; struct Tree原创 2020-08-26 14:17:53 · 214 阅读 · 0 评论 -
对称的二叉树,按之字形顺序打印二叉树,把二叉树打印成多行(剑指offer58-60)c++版本
#include <iostream>#include <vector>#include <stack>#include <queue>using namespace std;struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};原创 2020-08-20 12:36:48 · 173 阅读 · 0 评论 -
链表中环的入口结点,删除链表中的重复结点,二叉树的下一个结点(剑指offer55-57)c++版本
#include <iostream>using namespace std;struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};struct TreeLinkNode { int val; struct TreeLinkNode *left; struct TreeLinkNode *right; struct TreeLinkNo原创 2020-08-18 13:31:35 · 134 阅读 · 0 评论 -
构建乘积数组,正则表达式匹配,表示数值的字符串,字符流中第一个不重复的字符(剑指offer51-54)c++版本
#include <iostream>#include <vector>#include <map>using namespace std;class Solution {public: //JZ51 构建乘积数组 vector<int> multiply(const vector<int>& A); //JZ52 正则表达式匹配 bool match(char* str, char* pattern); //JZ5原创 2020-08-17 15:43:05 · 182 阅读 · 0 评论 -
求1+2+..+n,不用加减乘除做加法,把字符串转换成整数,数组中重复的数字(剑指offer47-50)c++版本
#include <iostream>using namespace std;class Solution {public: //JZ47 求1+2+3+...+n int Sum_Solution(int n); //JZ48 不用加减乘除做加法 int Add(int num1, int num2); //JZ49 把字符串转换成整数 int MAX_49 = 0; int StrToInt(string str); int ispositive(string st原创 2020-08-17 11:32:26 · 174 阅读 · 0 评论 -
左旋转字符串,翻转单词顺序列,扑克牌顺子,圆圈中最后剩下的数(剑指offer43-46)c++版本
#include <iostream>#include <vector>#include <algorithm>#include <list>using namespace std;class Solution {public: //JZ43 左旋转字符串 string LeftRotateString(string str, int n); void Reverse(string &str, int begin, int en原创 2020-08-13 17:56:38 · 209 阅读 · 0 评论 -
数组中只出现一次的数字,和为S的连续正数序列,和为S的两个数字(剑指offer40-42)c++版本
#include <iostream>#include <vector>#include <climits>using namespace std;class Solution {public: //JZ40 数组中只出现一次的数字 void FindNumsAppearOnce(vector<int> data, int* num1, int *num2); int findfirstof1(vector<int> data)原创 2020-08-13 15:34:37 · 125 阅读 · 0 评论 -
两个链表的第一个公共结点,数字在升序数组中出现的次数,二叉树的深度,平衡二叉树(剑指offer36-39)c++版本
#include <iostream>#include <vector>#include <algorithm>using namespace std;struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};struct TreeNode { int val; struct TreeNode *left; str原创 2020-08-12 16:08:40 · 145 阅读 · 0 评论 -
把数组排成最小的数,丑数,第一个只出现一次的字符,数组中的逆序对(剑指offer32-35)c++版本
#include <iostream>#include <vector>#include <algorithm>#include <string>#include <map>using namespace std;class Solution {public: //JZ32 把数组排成最小的数 string PrintMinNumber(vector<int> numbers); static bool com原创 2020-08-12 14:12:03 · 144 阅读 · 0 评论 -
数组中出现次数超过一半的数字,最小的k个数,连续子数组的最大和,整数中1出现的次数(剑指offer28-31)c++版本
#include <iostream>#include <vector>using namespace std;class Solution {public: //JZ28 数组中出现次数超过一半的数字 int MAX = 0; int MoreThanHalfNum_Solution(vector<int> numbers); bool ismorenum(vector<int> numbers, int len, int result原创 2020-08-11 15:21:43 · 156 阅读 · 0 评论 -
二叉搜索树与双向链表、字符串的排列(剑指offer26-27)c++版本
#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {原创 2020-08-10 18:18:36 · 163 阅读 · 0 评论 -
二叉树中和为某一值的路径、复杂链表的复制(剑指offer 24-25)c++版本
#include <iostream>#include <vector>using namespace std;struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};struct RandomListNode { int label; struct R原创 2020-08-10 15:15:38 · 132 阅读 · 0 评论 -
栈的压入、弹出序列,从上往下打印二叉树,二叉搜索树的后序遍历序列(剑指offer21-23)c++版本
#include <iostream>#include <vector>#include <stack>#include <queue>using namespace std;struct TreeNode { int val; struct TreeNode* left; struct TreeNode* right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};原创 2020-08-09 10:18:32 · 184 阅读 · 0 评论 -
二叉树的镜像、顺时针打印矩阵、包含min函数的栈(剑指offer18-20)c++版本
转载请注明出处。#include <iostream>#include <vector>#include <stack>using namespace std;struct TreeNode { int val; struct TreeNode* left; struct TreeNode* right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};class Soluti原创 2020-08-08 17:08:30 · 178 阅读 · 0 评论 -
变态跳台阶、矩形覆盖(剑指offer9-10)c++版本
转载请标明出处#include <iostream>using namespace std;void test1();void test2();class Solution {public: int MAX = 0; //JF9 变态跳台阶 int jumpFloorII(int number); //JF10 矩形覆盖 int rectCover(int number);};int Solution::jumpFloorII(int number) { //原创 2020-08-08 12:35:40 · 132 阅读 · 0 评论 -
反转链表、合并两个排序的链表、树的子结构(剑指offer15-17)c++版
转载请标明出处。#include <iostream>using namespace std;struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) :原创 2020-08-06 16:46:24 · 110 阅读 · 0 评论 -
二进制中1的个数、数值的整数次方、调整数组顺序使奇数位于偶数前面、链表中倒数k个结点(剑指offer11-14)c++版
代码可以跑通,转载请注明出处。#include <iostream>#include <vector>#include <climits>using namespace std;struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};void test1();//JZ11void test2();//JZ12v原创 2020-08-06 14:44:37 · 149 阅读 · 0 评论 -
二维数组查找、替换空格、从头到尾打印链表、重建二叉树(剑指offer1-4)c++版
代码,全部可以跑通,转载请表明出处。#include<iostream>#include<vector>#include<cstring>void test1();void test2();void test3();using namespace std;struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }原创 2020-07-31 16:53:14 · 172 阅读 · 0 评论 -
c++经典问题——最大间隙问题的求解
c++经典问题——最大间隙问题的求解//最大间隙问题//利用鸽巢原理。先求出数组中的最大值和最小值,将[min,max]分成n-1个等宽的区间(水桶)//将min置成第一个区间的下确界,max置成最后一个区间的上确界;将剩余的n-2个元素放入对应的//区间中,由鸽巢原理知,必然存在一个空的区间,最大间隙在该区间的两端的元素之间取得#include <iostream>#in...原创 2018-12-18 19:23:24 · 1769 阅读 · 0 评论