02 2019 档案
摘要:void BFSLayer(BinaryTreeNode* pRoot) { if(pRoot==nullptr) return; queue<BinaryTreeNode*> pNode; int curLayer=1,nextLayer=0; pNode.push(pRoot); while(!
阅读全文
摘要:void BFS(BinaryTreeNode* pRoot) { if(pRoot==nullptr) { cout<<"empty binary tree!"<<endl; return; } queue<BinaryTreeNode*>pNode; pNode.push(pRoot); whi
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 using namespace std; 4 5 const int MAXN=1000; 6 const int INF=10000000; 7 8 template<typename T>class Stack
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 using namespace std; 4 5 void PrintMatrixInCircle(int** matrix,int rows,int columns,int start) 6 { 7 int en
阅读全文
摘要:真题链接:https://www.nowcoder.com/test/8537269/summary 第一题: 1 #include"iostream" 2 #include"algorithm" 3 #include"stdio.h" 4 using namespace std; 5 const
阅读全文
摘要:1 void MirrorIteratively(BinaryTreeNode* pRoot) 2 { 3 if(pRoot == nullptr) 4 return; 5 6 std::stack<BinaryTreeNode*> stackTreeNode; 7 stackTreeNode.pu
阅读全文
摘要:#include"iostream" #include"stdio.h" #include"math.h" using namespace std; struct BinaryTreeNode { double m_Value; BinaryTreeNode* m_pLeft; BinaryTree
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 #include"math.h" 4 using namespace std; 5 6 struct BinaryTreeNode 7 { 8 double m_Value; 9 BinaryTreeNode* m
阅读全文
摘要:自己答案: 1 ListNode* MergeTwoSortedList(ListNode* pHead1,ListNode* pHead2) 2 { 3 if(pHead1==nullptr&&pHead2==nullptr) 4 return nullptr; 5 6 if(pHead1==nu
阅读全文
摘要:函数: 1 ListNode* MeetingNode(ListNode* pHead) 2 { 3 if(pHead==nullptr) 4 return nullptr; 5 ListNode* quickNode=pHead; 6 ListNode* slowNode=pHead; 7 8 w
阅读全文
摘要:注意代码的鲁棒性! 函数: 1 ListNode* TheLastKthNode(ListNode* pHead,int k) 2 { 3 if(pHead==nullptr || k<=0) 4 return nullptr; 5 ListNode* quickNode=pHead; 6 List
阅读全文
摘要:1 #include"iostream" 2 using namespace std; 3 4 bool IsInt(const char **str); 5 bool IsUnsignInt(const char **str); 6 7 bool IsNumeric(const char* str
阅读全文
摘要:1 #include"iostream" 2 using namespace std; 3 4 bool MatchCore(char*str,char* pattern); 5 6 bool Match(char* str,char* pattern) 7 { 8 if(str==nullptr|
阅读全文
摘要:1 // 面试题18(二):删除链表中重复的结点 2 // 题目:在一个排序的链表中,如何删除重复的结点?例如,在图3.4(a)中重复 3 // 结点被删除之后,链表如图3.4(b)所示。 4 5 #include <cstdio> 6 #include "List.h" 7 8 void Dele
阅读全文
摘要:1 #include"List.h" 2 3 void DeleteNode(ListNode** pHead,ListNode* pToBeDeleted) 4 { 5 if(*pHead==nullptr || pToBeDeleted==nullptr) 6 return; 7 if(pToB
阅读全文
摘要:1 #include"stdio.h" 2 #include"stdlib.h" 3 #include"iostream" 4 using namespace std; 5 6 struct ListNode 7 { 8 int m_Value; 9 ListNode* m_pNext; 10 };
阅读全文
摘要:1 #include"iostream" 2 #include"string.h" 3 using namespace std; 4 5 bool AddOne(char *number,int n); 6 void PrintNumber(char *number,int n); 7 8 void
阅读全文
摘要:1 // 面试题16:数值的整数次方 2 // 题目:实现函数double Power(double base, int exponent),求base的exponent 3 // 次方。不得使用库函数,同时不需要考虑大数问题。 4 5 #include <iostream> 6 #include
阅读全文
摘要:1 #include"iostream" 2 using namespace std; 3 4 int CountDifferentBit(int m,int n) 5 { 6 int cnt=0,diff=m^n; 7 while(diff) 8 { 9 cnt++; 10 diff=(diff-
阅读全文
摘要:1 #include"iostream" 2 using namespace std; 3 4 bool IsTwoPower(int n) 5 { 6 return !((n-1)&n); 7 } 8 9 int main() 10 { 11 int n; 12 while(cin>>n) 13
阅读全文
摘要:1 // 面试题15:二进制中1的个数 2 // 题目:请实现一个函数,输入一个整数,输出该数二进制表示中1的个数。例如 3 // 把9表示成二进制是1001,有2位是1。因此如果输入9,该函数输出2。 4 5 #include <cstdio> 6 7 int NumberOf1_Solution
阅读全文
摘要:// 面试题14:剪绳子 // 题目:给你一根长度为n绳子,请把绳子剪成m段(m、n都是整数,n>1并且m≥1)。 // 每段的绳子的长度记为k[0]、k[1]、……、k[m]。k[0]*k[1]*…*k[m]可能的最大乘 // 积是多少?例如当绳子的长度是8时,我们把它剪成长度分别为2、3、3的三
阅读全文
摘要:1 #include"iostream" 2 using namespace std; 3 4 int GetMinNumber(int *data,int len) 5 { 6 int left=0,right=len-1,mid; 7 8 while(left<right-1) 9 { 10 m
阅读全文
摘要:1 #include"iostream" 2 #include"random" 3 using namespace std; 4 5 /* 6 void Swap(int &a,int &b) 7 { 8 int tmp; 9 tmp=a; 10 a=b; 11 b=tmp; 12 } 13 */
阅读全文
摘要:个人答案: 1 #include"iostream" 2 #include"stdio.h" 3 #include"string.h" 4 using namespace std; 5 typedef long long ll; 6 const int MAXN=10000; 7 8 ll fib[
阅读全文
摘要:#include "Queue.h" // 测试代码 void Test(char actual, char expected) { if(actual == expected) printf("Test passed.\n"); else printf("Test failed.\n"); } i
阅读全文
摘要:1 // 面试题8:二叉树的下一个结点 2 // 题目:给定一棵二叉树和其中的一个结点,如何找出中序遍历顺序的下一个结点? 3 // 树中的结点除了有两个分别指向左右子结点的指针以外,还有一个指向父结点的指针。 4 5 #include <stdio.h> 6 7 struct BinaryTree
阅读全文
摘要:1 // 面试题7:重建二叉树 2 // 题目:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输 3 // 入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1, 4 // 2, 4, 7, 3, 5, 6, 8}和中序遍历序列{4, 7, 2, 1, 5, 3,
阅读全文
摘要:#include"iostream" #include"stdio.h" #include"stack" using namespace std; struct ListNode { int value; ListNode *pNext; }; ListNode* CreatListNode(int
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 using namespace std; 4 5 int* ArrayMerge(int *a,int aLen,int *b,int bLen) 6 { 7 int aIndex=aLen-1,bIndex=bL
阅读全文
摘要:利用STL: 1 #include"iostream" 2 #include"stdio.h" 3 #include"algorithm" 4 using namespace std; 5 6 string ReplaceBlank(string src) 7 { 8 if(src.find(" "
阅读全文
摘要:1 // 面试题4:二维数组中的查找 2 // 题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按 3 // 照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个 4 // 整数,判断数组中是否含有该整数。 5 6 #include <cstdio> 7 8 b
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 using namespace std; 4 typedef long long ll; 5 6 ll f(ll n) 7 { 8 ll fn=0,ntemp=n; 9 ll step; 10 for(step=1
阅读全文
摘要:1 #include"iostream" 2 #include"string" 3 #include"vector" 4 #include"sstream" 5 #include"stdio.h" 6 using namespace std; 7 8 int main() 9 { 10 string
阅读全文
摘要:1 #include"iostream" 2 #include"string" 3 #include"string.h" 4 #include"vector" 5 #include"algorithm" 6 using namespace std; 7 8 vector<string> subStr
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 #include"string.h" 4 #include"vector" 5 using namespace std; 6 7 const int MAXN=100005; 8 9 pair<int,string
阅读全文
摘要:1 #include"iostream" 2 #include"stdio.h" 3 using namespace std; 4 5 void ShellSort(int *data,int left,int right) 6 { 7 int len=right-left+1; 8 int d=l
阅读全文
摘要:一、题意:长度为n+1的数组里的所有数字都在1~n的范围内,找出任意一个重复复的数字,但不能修改原数组。 二、思路: 1、创建一个长度为n+1的辅助数组,在O(n)的复杂度里面可以解决这个问题,空间复杂度也为O(n); 2、时间换空间,采用类似于二分查找的方式,用中间数字对数组中的数字进行划分,然后
阅读全文
摘要:一、题意:一个数组中任意一个重复的数字 二、思路: 1.因为题中给的数字大小范围在0~n-1,因此可以直接用一个数据来记录数字是否重复出现过。时间复杂度为O(n),空间复杂度也为O(n); 2.先给数组排序,然后依次便利。时间复杂度为O(nlogn); 3.利用下标和对应数字的关系对数组进行重排,这
阅读全文
摘要:一、题意:对赋值操作符进行重定义,使其可以进行类对象的赋值 二、代码: 1 #include<cstring> 2 #include<cstdio> 3 #include<iostream> 4 using namespace std; 5 6 class CMyString 7 { 8 publi
阅读全文