摘要:
Same Tree2013.12.31 22:56Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Solution: Check the root, the left subtree and the right subtree, recursively. That's the 阅读全文
摘要:
Recover Binary Search Tree2013.12.31 19:00Two 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?confused what"{1,#,2,3}"means? 阅读全文
摘要:
Validate Binary Search Tree2013.12.31 18:48Given 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 阅读全文
摘要:
Unique Binary Search Trees2013.12.31 18:37Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / ... 阅读全文
摘要:
Binary Tree Inorder Traversal2013.12.31 18:26Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note:Recursive solution is trivial, could you do it iteratively?confused what"{1,#,2,3}"means?> read more 阅读全文
摘要:
Restore IP Addresses2013.12.31 18:06Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order does not matter)Solution: Given a number strin 阅读全文
摘要:
Reverse Linked List II2013.12.31 16:00Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 ≤m≤n≤ length of list.Solution1: Rever 阅读全文