摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?1.O(n) space solution中序遍历该BST,得到所有整数对齐排好序,对节点重新进行赋值 1 /** 2 * Definition for bina. 阅读全文
posted @ 2013-08-15 22:16 feiling 阅读(372) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node's key.Both the left and ri 阅读全文
posted @ 2013-08-15 21:55 feiling 阅读(268) 评论(0) 推荐(0) 编辑
摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.[解题思路]在头结点之前添加safeguard,防止处理一开始就是连续节点的情况当发现连续节点时,line 阅读全文
posted @ 2013-08-15 13:09 feiling 阅读(253) 评论(0) 推荐(0) 编辑