摘要:
昨天临近要睡觉的时候做了一个leetcode题目,“Recover BST”,算法很容易就想到了,直接找出两个异常点就好了,但是我写的算法是用栈实现的非递归遍历,空间复杂度是O(N),虽然比递归的要好点,但是题目说明里面那句“如果能用constant space ”却让我百思不得其解。难道我的解法不是最精简的? 我的解法说白了就是个preorder traversal,难道有可以不用traver... 阅读全文
摘要:
1.题目描述 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its s... 阅读全文
摘要:
1.题目描述 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follo... 阅读全文
摘要:
1.题目描述 Given two binary trees, write a function to check if they are equal or not. Two binary trees are considere... 阅读全文
摘要:
1.题目描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example... 阅读全文