MCPcopy Create free account
hub / github.com/douchuan/algorithm / RecoverBinarySearchTree

Class RecoverBinarySearchTree

src/tree/binary/traverse.rs:107–107  ·  view source on GitHub ↗

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: 输入:root = [1,3,null,null,2] 输出:[3,1,null,null,2] 解释:3 不能是 1 左孩子,因为 3 > 1 。交换 1 和 3 使二叉搜索树有效。 示例 2: 输入:root = [3,1,4,null,null,2] 输出:[2,1,4,null,null,3] 解释:2 不能在 3 的右子树中,因

Source from the content-addressed store, hash-verified

105/// 输出:[2,1,4,null,null,3]
106/// 解释:2 不能在 3 的右子树中,因为 2 < 3 。交换 2 和 3 使二叉搜索树有效。
107pub struct RecoverBinarySearchTree;
108
109/// Given two binary trees, write a function to check if they are equal or not.
110/// Two binary trees are considered equal if they are structurally identical and

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected