摘要: 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。(注意:这两个序列的长 阅读全文
posted @ 2019-09-24 15:30 夜深不自知 阅读(843) 评论(0) 推荐(0) 编辑
摘要: 使用数组实现二路归并排序 include include include include include include using namespace std; void merge(vector&arr,int left1,int right1,int left2,int right2){ in 阅读全文
posted @ 2019-09-24 09:13 夜深不自知 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 题目描述 在你面前有一个n阶的楼梯(n =100且n include include using namespace std; string add(string &a,string &b){ int tmp=0; int i=a.size() 1,j=b.size() 1; string res= 阅读全文
posted @ 2019-09-23 13:04 夜深不自知 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 通过链表实现归并排序 include using namespace std; struct ListNode{ int val; ListNode next; ListNode(int x):val(x),next(NULL){ } }; ListNode merge(ListNode list1 阅读全文
posted @ 2019-09-22 21:42 夜深不自知 阅读(485) 评论(0) 推荐(0) 编辑
摘要: 用链表合并两个有序列表。 include using namespace std; struct ListNode{ int val; ListNode next; ListNode(int x):val(x),next(NULL){ } }; ListNode merge(ListNode lis 阅读全文
posted @ 2019-09-21 17:09 夜深不自知 阅读(785) 评论(0) 推荐(0) 编辑
摘要: 根据前序遍历和中序遍历还原二叉树: include include include include using namespace std; struct TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) : val 阅读全文
posted @ 2019-09-20 21:25 夜深不自知 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 普通快速排序代码如下 include include include include using namespace std; int getindex(vector&arr,int left,int right){ int m=arr[left]; while(left=m) right ; ar 阅读全文
posted @ 2019-09-20 20:01 夜深不自知 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 题目描述 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。 class Solution { public: bool validate(vector&arr,int left,int right){ if(l 阅读全文
posted @ 2019-09-20 15:35 夜深不自知 阅读(325) 评论(0) 推荐(0) 编辑
摘要: 给定一个字符串,求出其中的最长回文子串。 include include include include using namespace std; int LongestPalindromicSubstring(string a){ int size=a.length(); vector dp(si 阅读全文
posted @ 2019-09-17 19:11 夜深不自知 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 在你面前有一个n阶的楼梯,你一步只能上1阶或2阶。 请问计算出你可以采用多少种不同的方式爬完这个楼梯。 输入描述: 一个正整数n(n include include using namespace std; string add(string&a,string&b){ string res; int 阅读全文
posted @ 2019-09-17 16:33 夜深不自知 阅读(118) 评论(0) 推荐(0) 编辑