剑指offer刷题
ChrisKyrie
这个作者很懒,什么都没留下…
展开
-
面试题11:旋转数组的最小数字
题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小值。例如,数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1 #include <iostream> #include <vector> using namespace std; int getMin(vector<int> buf, int index1, int index2) { int retNum =原创 2020-10-09 21:27:07 · 90 阅读 · 0 评论 -
面试题24:反转链表
题目:定义一个函数,输入一个链表的头节点,反转该链表并输出反转链表的头节点。 #include <iostream> using namespace std; typedef struct listnode { int val; struct listnode* next; }ListNode; void creatList(ListNode** head) { int num; cin >> num; ListNode* tail = nullptr; wh原创 2020-10-08 22:13:10 · 78 阅读 · 0 评论 -
面试题9:用两个栈实现队列
题目:用两个栈实现队列功能 #include <iostream> #include <stack> using namespace std; template<class T> class MyQueue { private: stack<T> s1; stack<T> s2; public: MyQueue(){} ~MyQueue(){} void pushData(T val) { s1.push(val); }原创 2020-10-04 15:56:21 · 81 阅读 · 0 评论 -
面试题6:从尾到头打印链表
题目:输入一个链表的头节点,从尾到头打印出每个节点的值 #include <iostream> #include <string> #include <cstdlib> #include <map> #include <vector> #include <algorithm> #include <thread> #include <array> #include <ctime> #include原创 2020-10-03 15:25:54 · 86 阅读 · 0 评论 -
面试题7:重建二叉树
题目:输入某二叉树的前序遍历和中序遍历的结果,请重建该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如:输入前序遍历{1,2,4,7,3,5,6,8}和中序遍历{4, 7, 2,1,5,3,8,6},请重建该二叉树。 #include <iostream> #include <string> #include <cstdlib> using namespace std; typedef struct treenode { int val; t原创 2020-10-03 15:14:11 · 110 阅读 · 0 评论 -
面试题5:替换空格
题目:请实现一个函数,把字符串中的每个空格替换成“%2d"。例如,请输入"We are happy",则输出”We%2dare%2dhappy“。 #include <iostream> #include <string> #include <cstdlib> using namespace std; int main() { char str[50] = " Hello World China!"; char *p1 = str + strlen(str)原创 2020-10-03 15:06:54 · 56 阅读 · 0 评论 -
面试题4:二维数组的查找
题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有这整数。 代码如下: #include <iostream> #include <vector> using namespace std; const int SIZE = 4; int main() { vector<vector<int>> buf(SIZE, vector<i原创 2020-10-03 15:07:23 · 97 阅读 · 0 评论