摘要: 1 #include 2 #include 3 using namespace std; 4 5 void Merge(vector& nums, const int first, const int mid, const int last, vector&temp) 6 { 7 i... 阅读全文
posted @ 2015-07-07 19:46 tjuloading 阅读(173) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 using namespace std; 4 5 void quickSort(vector& nums, const int lpos, const int rpos) 6 { 7 if(lpos = key)16 ... 阅读全文
posted @ 2015-07-07 17:53 tjuloading 阅读(157) 评论(0) 推荐(0)
摘要: 思路: 没啥好说的,BFS。C++: 1 #include 2 #include 3 using namespace std; 4 5 struct TreeNode { 6 int val; 7 TreeNode *left; 8 TreeNode *right; ... 阅读全文
posted @ 2015-07-06 22:38 tjuloading 阅读(163) 评论(0) 推荐(0)
摘要: 思路: 不停地压栈,直到栈头元素与弹出序列的首元素相等则出栈,同时弹出序列后移;若不相等则一直保持压栈,直到压入所有元素后弹出序列仍不为空,则说明无法匹配。C++: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 bo... 阅读全文
posted @ 2015-07-06 22:17 tjuloading 阅读(139) 评论(0) 推荐(0)
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.题意: 一颗二叉搜索树中有2个结点的元素被误换了,要求恢复二叉搜索树的... 阅读全文
posted @ 2015-07-06 19:46 tjuloading 阅读(216) 评论(0) 推荐(0)
摘要: Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a... 阅读全文
posted @ 2015-07-06 15:54 tjuloading 阅读(122) 评论(0) 推荐(0)
摘要: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Callingnext()will return the next... 阅读全文
posted @ 2015-07-06 14:23 tjuloading 阅读(172) 评论(0) 推荐(0)
摘要: Given an integer, write a function to determine if it is a power of two.思路: 如果一个数是2的Power,那么该数的二进制串中只有一位为1,其余都为0。执行一次n & (n - 1)可消除最低位的一个1,若消除后为0,则说明... 阅读全文
posted @ 2015-07-06 12:35 tjuloading 阅读(306) 评论(0) 推荐(0)
摘要: Given a binary search tree, write a functionkthSmallestto find thekth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST's tota... 阅读全文
posted @ 2015-07-02 21:10 tjuloading 阅读(442) 评论(0) 推荐(0)
摘要: Given a range [m, n] where 0 >=1; 7 n>>=1; 8 offset++; 9 }10 return m> 110 n = n >> 111 ... 阅读全文
posted @ 2015-07-01 21:37 tjuloading 阅读(537) 评论(0) 推荐(0)