-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path99.恢复二叉搜索树.cpp
83 lines (80 loc) · 1.29 KB
/
99.恢复二叉搜索树.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* @lc app=leetcode.cn id=99 lang=cpp
*
* [99] 恢复二叉搜索树
*
* https://leetcode-cn.com/problems/recover-binary-search-tree/description/
*
* algorithms
* Hard (53.82%)
* Likes: 100
* Dislikes: 0
* Total Accepted: 7K
* Total Submissions: 13.1K
* Testcase Example: '[1,3,null,null,2]'
*
* 二叉搜索树中的两个节点被错误地交换。
*
* 请在不改变其结构的情况下,恢复这棵树。
*
* 示例 1:
*
* 输入: [1,3,null,null,2]
*
* 1
* /
* 3
* \
* 2
*
* 输出: [3,1,null,null,2]
*
* 3
* /
* 1
* \
* 2
*
*
* 示例 2:
*
* 输入: [3,1,4,null,null,2]
*
* 3
* / \
* 1 4
* /
* 2
*
* 输出: [2,1,4,null,null,3]
*
* 2
* / \
* 1 4
* /
* 3
*
* 进阶:
*
*
* 使用 O(n) 空间复杂度的解法很容易实现。
* 你能想出一个只使用常数空间的解决方案吗?
*
*
*/
// @lc code=start
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void recoverTree(TreeNode* root) {
}
};
// @lc code=end