Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,36 @@ public class Solution {
}
```

#### Swift

```swift
/* public class TreeNode {
* var val: Int
* var left: TreeNode?
* var right: TreeNode?
* init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
* }
* }
*/

class Solution {
func mirrorTree(_ root: TreeNode?) -> TreeNode? {
guard let root = root else {
return nil
}
let temp = root.left
root.left = root.right
root.right = temp
_ = mirrorTree(root.left)
_ = mirrorTree(root.right)
return root
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* public class TreeNode {
* var val: Int
* var left: TreeNode?
* var right: TreeNode?
* init(_ val: Int) {
* self.val = val
* self.left = nil
* self.right = nil
* }
* }
*/

class Solution {
func mirrorTree(_ root: TreeNode?) -> TreeNode? {
guard let root = root else {
return nil
}
let temp = root.left
root.left = root.right
root.right = temp
_ = mirrorTree(root.left)
_ = mirrorTree(root.right)
return root
}
}