摘要: 1234567891011121314151617181920212223242526272829303132333435363738394041424344/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tr... 阅读全文
posted @ 2016-03-16 21:10 copperface 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 1234567891011121314151617181920212223242526272829303132333435363738394041424344class Solution {public: string replaceSpace(string str) { stack Mystack; int length=str.length(); int bla... 阅读全文
posted @ 2016-03-16 21:09 copperface 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 12345678910111213141516171819202122232425class Solution {public: void reOrderArray(vector &array) { vector newArray; queue evenArray; for(int i=0;i<array.size();i++) { ... 阅读全文
posted @ 2016-03-16 21:08 copperface 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 1234567891011121314151617181920212223242526272829303132333435class Solution {public: double Power(double base, int exponent) { int isOdd; if(0.0==base)return 0; if(exponent>0) ... 阅读全文
posted @ 2016-03-16 21:08 copperface 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 利用两个间隔为k的指针来实现倒数第k个1234567891011121314151617181920212223242526272829303132/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*/class S... 阅读全文
posted @ 2016-03-16 21:07 copperface 阅读(129) 评论(0) 推荐(0) 编辑
摘要: way1:12345678910111213141516171819202122232425262728293031323334353637383940414243/*struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { }};*... 阅读全文
posted @ 2016-03-16 21:06 copperface 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 判断: 如果下一个弹出的数字刚好是栈顶元素,那么直接弹出如果下一个弹出的数字不在栈顶,我们要把压栈序列中,还没有入栈的数字压入辅助栈,知道把下一个需要弹出的数字压入栈顶如果所有的数字都入栈,但是仍然没有找到下一个弹出的数字,那么该序列不可能为弹出序列。123456789101112131415161718192021222324class Solution {public: bool Is... 阅读全文
posted @ 2016-03-16 21:05 copperface 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 最后一个元素是 根节点。 左子树的元素都小于根节点,右子树都大于根节点然后递归判断123456789101112131415161718192021222324252627282930313233343536373839class Solution {public: bool VerifySquenceOfBST(vector sequence) { int size=seq... 阅读全文
posted @ 2016-03-16 21:04 copperface 阅读(922) 评论(0) 推荐(0) 编辑
摘要: 剑指offer 二叉搜索树与双向链表 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。思路,中序遍历压入vector,然后调整12345678910111213141516171819202122232425262728293031323334/*struct TreeNode { int val; struct... 阅读全文
posted @ 2016-03-16 21:02 copperface 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 时间复杂度O(3N)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950/*struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode... 阅读全文
posted @ 2016-03-16 21:02 copperface 阅读(296) 评论(0) 推荐(0) 编辑