![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
文章平均质量分 51
KalaerSun
总有许多风景等着你去发现,能做自己曾做不了的,就是最好的生活
展开
-
剑指offer 二叉搜索树与双向链表
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { publi...原创 2018-03-27 10:16:53 · 77 阅读 · 0 评论 -
剑指offer 和为S的两个数字
class Solution {public: vector<int> FindNumbersWithSum(vector<int> array,int sum) { vector<int> result; int i=0; int j=array.size()-1; while(i<...原创 2018-04-09 15:31:28 · 170 阅读 · 1 评论 -
剑指offer 和为S的连续正数序列
class Solution {public: vector<vector<int> > FindContinuousSequence(int sum) { vector<vector<int>> result; int hign=2,low=1; while(hign>low) ...原创 2018-04-09 15:17:01 · 72 阅读 · 0 评论 -
剑指offer 复杂链表的复制
/*struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : label(x), next(NULL), random(NULL) { }};*/class Solution {public: ...原创 2018-03-27 09:44:38 · 82 阅读 · 0 评论 -
剑指offer 数组中只出现一次的数字
class Solution {public: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { int Xor=0; for(int i=0;i<data.size();++i) { Xor^=data[i]; ...原创 2018-04-09 13:57:11 · 117 阅读 · 0 评论 -
剑指offer 平衡二叉树
class Solution {public: bool IsBalanced(TreeNode *root,int &depth) { if(root==NULL) { return true; } int left=0; int right=0; i...原创 2018-04-09 12:43:31 · 85 阅读 · 0 评论 -
剑指offer 二叉树这种和为某一值的路径
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution { void DFS_Fi...原创 2018-03-26 14:56:18 · 121 阅读 · 0 评论 -
剑指offer 二叉搜索树的后序遍历序列
class Solution {public:bool isBSTree(vector<int> sequence,int l,int r) { if(r<=l) { return true; } int i=l; for(;i<r;i++) ...原创 2018-03-26 13:13:13 · 77 阅读 · 0 评论 -
剑指offer 从上往下打印二叉树
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: vec...原创 2018-03-26 12:52:22 · 77 阅读 · 0 评论 -
剑指offer 字符串的排列
class Solution {public: vector<string> Permutation(string str) { //可以用递归来做 &n原创 2018-03-27 10:53:58 · 128 阅读 · 0 评论 -
剑指offer 数组中出现次数超过一半的数字
class Solution {public: int MoreThanHalfNum_Solution(vector<int> numbers) { int n = numbers.size(); &原创 2018-03-27 11:07:22 · 97 阅读 · 0 评论 -
剑指offer 最小的k个数
链接:https://www.nowcoder.com/questionTerminal/6a296eb82cf844ca8539b57c23e6e9bf来源:牛客网class Solution {public: vector<int> GetLeastNumbers_Solution(vector<int> inpu...原创 2018-03-27 11:54:33 · 151 阅读 · 0 评论 -
剑指offer 构建乘积数组
class Solution {public: vector<int> multiply(const vector<int>& A) { int length=A.size(); vector<int> B(length,1); if(length!=0) { ...原创 2018-04-12 19:17:43 · 92 阅读 · 0 评论 -
剑指offer 数组中重复的数字
class Solution {public: // Parameters: // numbers: an array of integers // length: the length of array numbers // duplication: (Output) the duplicated nu...原创 2018-04-12 18:39:07 · 113 阅读 · 0 评论 -
剑指offer 把字符串转换成整数
class Solution {public: int StrToInt(string str) { int n=str.size(),s=1; long long res=0; if(!n) return 0; if(str[0]=='-') s=-1; for(int i=(str[0]=='-'||st...原创 2018-04-12 18:00:26 · 164 阅读 · 0 评论 -
剑指offer 不使用加减乘除做加法
class Solution {public: int Add(int num1, int num2) { while(num2!=0) { int temp=num1^num2; num2 = (num1&num2)<<1; num1=temp; ...原创 2018-04-12 17:41:11 · 115 阅读 · 0 评论 -
剑指offer 求1+2+3+4+。。。+n
class Solution {public: int Sum_Solution(int n) { int result=n; result&&(result+=Sum_Solution(n-1)); return result; }};题目要求不能循环判断等关键字 所有借助&& 短路运算符...原创 2018-04-12 17:19:42 · 132 阅读 · 0 评论 -
剑指offer 孩子们的游戏
约瑟夫环的问题class Solution {public: int LastRemaining_Solution(int n, int m) { if(n<1||m<1) return -1; int *array= new int[n];//用数组模拟环 int i=-1,step=0,count=n; ...原创 2018-04-12 17:03:12 · 216 阅读 · 0 评论 -
剑指offer 扑克牌顺子
扑克问题 1 ,大小王是 0 即可看作是任意的数字 先统计0的个数 2,如果有两张一样的牌,一样的数字形成对(不是0)那就不可能是顺子 3,判断相邻两张扑克的差值 如果大于零的个数 则不可能用0补全成为顺子 01456 1与4相差2 但是只有一个0就没法补全class Solution {public: bool IsContinuous( vector<int>...原创 2018-04-12 15:39:50 · 98 阅读 · 0 评论 -
翻转单词序列
class Solution {public: void ReverseWord(string &str,int start,int end) { while(start<end) { swap(str[start++],str[end--]); } } string Reve...原创 2018-04-12 14:57:44 · 153 阅读 · 0 评论 -
左旋转字符串
class Solution {public: string LeftRotateString(string str, int n) { int len = str.length(); if(len==0) return ""; n=n%len; str+=str; return str.substr(n,le...原创 2018-04-12 11:02:22 · 102 阅读 · 0 评论 -
剑指offrer 栈的压入,弹出序列
class Solution {public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { if(pushV.empty()||popV.empty()||pushV.size()!=popV.size()) { return false; ...原创 2018-03-26 12:25:58 · 89 阅读 · 0 评论 -
剑指offer 包含min函数的栈
class Solution {public: stack<int> stack1,stack2; void push(int value) { stack1.push(value); if(stack2.empty()) { stack2.push(value); }else i...原创 2018-03-26 12:14:48 · 84 阅读 · 0 评论 -
剑指offer 顺时针打印矩阵
题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10. 题目解释class Solution {public: vector<int> printMa...原创 2018-03-26 11:51:03 · 125 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树
#include #include #define ElementType inttypedef struct TNode *Position;typedef Position Tree;struct TNode{ ElementType Data; Tree Left; Tree Right; int flag;};Tree makeTree(in原创 2017-03-24 19:32:34 · 178 阅读 · 0 评论 -
软件测试 功能测试 java求前一天
用java实现求前一天,用读取文件的方式读取当前时间 首先创建一个time.txt1996-3-11997-3-12005-11-102010-9-8然后创建一个文件读取类和一个键值对包装类(好吧,这个后来没用上因为发现不需要序号这个东西)package file;import java.io.BufferedReader;import java.io.File;import原创 2017-03-14 20:04:49 · 658 阅读 · 0 评论 -
05-树8 File Transfer
05-树8 File TransferWe have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible to send a fi原创 2017-03-30 20:48:53 · 323 阅读 · 0 评论 -
05-树7 堆中的路径
将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数NNN和MMM(≤1000\le 1000≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的NNN个要被插入一个初始为空的小顶堆的整数。最后一行给出MMM个下标。输出格式:对输入原创 2017-03-30 15:39:56 · 230 阅读 · 0 评论 -
04-树7 二叉搜索树的操作集
本题要求实现给定二叉搜索树的5种常用操作。函数接口定义:BinTree Insert( BinTree BST, ElementType X );BinTree Delete( BinTree BST, ElementType X );Position Find( BinTree BST, ElementType X );Position FindMin( BinTree BST )原创 2017-03-22 15:10:38 · 260 阅读 · 0 评论 -
03-树2. List Leaves (25)
03-树2. List Leaves (25)Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.Input Specification:Each input file contains one test case. For each case原创 2017-03-21 20:57:32 · 294 阅读 · 0 评论 -
合并单向有序列表
#include #include typedef int ElementType;typedef struct Node *PtrToNode;typedef struct Node { ElementType Data; PtrToNode Next;};typedef PtrToNode List;//链表指针List Read()原创 2017-03-21 01:06:02 · 253 阅读 · 0 评论 -
复习 数据结构 照着慕课来吧第一篇 最大子列和
#include /*第一种是穷举法,实际上是计算所有的子列求出其中的最大值*/int MaxSum(int a[],int N){int thisSum,Maxsum=0;int i,j,k;for(i=0;ifor(j=i;j{thisSum=0;for(k=i;kthisSum+=a[k];if(thisSum>Maxsum){原创 2017-03-20 20:04:56 · 306 阅读 · 0 评论 -
数据结构复习第一天单链表的操作集合
#include #include #include typedef int ElemType;typedef struct LNode{ ElemType data; struct LNode *next;}LNode,*LinkList;LinkList Forward_Insert(){ ElemType n,cur; LinkList L;原创 2018-01-04 16:30:45 · 197 阅读 · 0 评论 -
链栈的操作集
#include #include #include typedef int ElemType;typedef struct Node{ ElemType data; struct Node *next;}StackNode,*LinkStack;void Init_LinkStack(LinkStack *s){ (*s)=(StackNode *)mal原创 2018-01-05 14:34:34 · 227 阅读 · 0 评论 -
剑指offer 整数中1出现的次数
class Solution {public: int NumberOf1Between1AndN_Solution(int n) { int count = 0;//1的个数 int i = 1;//当前位 int current = 0,after = 0,before = 0;&nbs...原创 2018-03-30 16:01:51 · 129 阅读 · 0 评论 -
剑指offer 二叉树的镜像
/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/class Solution {public: voi...原创 2018-03-26 11:31:51 · 70 阅读 · 0 评论 -
剑指offer 二叉树的深度
/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { publi...原创 2018-04-08 10:50:34 · 80 阅读 · 0 评论 -
剑指offer 数字在排序数组中出现的次数
class Solution {public: int GetNumberOfK(vector<int> data ,int k) { int lower = getLower(data,k); int upper = getUpper(data,k); return upper - lower; } int g...原创 2018-04-08 10:43:59 · 81 阅读 · 0 评论 -
剑指offer 两个链表的第一个公共节点
/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class Solution {public: ListNode* FindFirstCommonNode( ListNode* pHe...原创 2018-04-08 10:03:16 · 78 阅读 · 0 评论 -
剑指offer 数组中的逆序对
class Solution {public: long long InversePairsCore(vector<int> &data,vector<int>&copy,int start,int end) { if(start==end) { copy[start]=data[en...原创 2018-03-30 19:38:18 · 100 阅读 · 0 评论