上一页 1 ··· 17 18 19 20 21

2016年4月18日

Construct Binary Tree from Preorder and Inorder Traversal

摘要: 题目要求给出前序和中序二叉树遍历结果,重建二叉树。树的节点值不存在冗余。 解法是给出目前处理的前序和中序的起始和结束的index。前序的第一个值为根节点的值,根据这个值在中序中查找index,从而在中序中划分左子树和右子树的遍历,递归求解,直至只有一个节点。注意为了进行中序遍历的高效查找,预先把值存 阅读全文

posted @ 2016-04-18 20:00 Sheryl Wang 阅读(209) 评论(0) 推荐(0) 编辑

2016年4月14日

Reverse Linked List

摘要: 本题是反转一个单链表,题目提示使用迭代和递归两种方式,属于比较基础的题目。 一,迭代方式:总体思路是从左到右遍历链表结点,依次反转连接关系。每次处理相邻的两个结点,从<None,head>这一对开始。代码如下: 代码中prev为每次结点对的先序结点,当head为None时,prev为目前链表的末结点 阅读全文

posted @ 2016-04-14 22:45 Sheryl Wang 阅读(131) 评论(0) 推荐(0) 编辑

2016年4月13日

Best Time to Buy and Sell Stock

摘要: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文

posted @ 2016-04-13 20:47 Sheryl Wang 阅读(140) 评论(0) 推荐(0) 编辑

2016年4月12日

Remove Duplicates from Sorted Array II

摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For example,Given sorted array nums = [1,1,1,2,2,3], Your function sho 阅读全文

posted @ 2016-04-12 21:31 Sheryl Wang 阅读(183) 评论(0) 推荐(0) 编辑

2016年4月11日

Reverse Integer

摘要: class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ flag = x 0: if result *10 > 2147483647 -a%10: r... 阅读全文

posted @ 2016-04-11 21:59 Sheryl Wang 阅读(127) 评论(0) 推荐(0) 编辑

2016年4月9日

Implement Stack using Queues

摘要: 这题是使用队列去实现栈,属于比较基础的题目。需要考虑的点在于队列为先进先出,即入队在队尾,但是出队在队首,而栈为先进后出,即出栈和入栈都在栈尾。需要实现的功能如下: push(x) -- Push element x onto stack. pop() -- Removes the element 阅读全文

posted @ 2016-04-09 23:13 Sheryl Wang 阅读(286) 评论(0) 推荐(0) 编辑

2014年8月9日

C++中const限定符的应用

摘要: const限定符用于限定变量或对象的值。const对象一旦创建其值不能再改变。在C++中,const与引用和指针相结合,有多种用法。下面将结合<C++ Primer>第五版的内容做一个较详细的介绍。 1.const对象初始化 const对象必须初始化,初始化可以是任意复杂的表达式,如: const 阅读全文

posted @ 2014-08-09 22:26 Sheryl Wang 阅读(392) 评论(0) 推荐(0) 编辑

上一页 1 ··· 17 18 19 20 21

导航