We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent acc662b commit da6ec4eCopy full SHA for da6ec4e
animation-simulation/二叉树/二叉树中序遍历(Morris).md
@@ -102,3 +102,34 @@ class Solution {
102
}
103
```
104
105
+Swift Code:
106
+
107
+```swift
108
+class Solution {
109
+ func inorderTraversal(_ root: TreeNode?) -> [Int] {
110
+ var list:[Int] = []
111
+ guard root != nil else {
112
+ return list
113
+ }
114
+ var p1 = root, p2: TreeNode?
115
+ while p1 != nil {
116
+ p2 = p1!.left
117
+ if p2 != nil {
118
+ while p2!.right != nil && p2!.right !== p1 {
119
+ p2 = p2!.right
120
121
+ if p2!.right == nil {
122
+ p2!.right = p1
123
+ p1 = p1!.left
124
+ continue
125
+ } else {
126
+ p2!.right = nil
127
128
129
+ list.append(p1!.val)
130
+ p1 = p1!.right
131
132
133
134
+}
135
+```
0 commit comments