-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeet226.swift
More file actions
31 lines (26 loc) · 762 Bytes
/
Leet226.swift
File metadata and controls
31 lines (26 loc) · 762 Bytes
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
//
// Leet226.swift
// Algorithm
//
// Created by dabeen on 2022/06/20.
//
import Foundation
func invertTree(_ root: TreeNode?) -> TreeNode? {
guard let root = root else { return nil }
let temp = root.right
root.right = invertTree(root.left)
root.left = invertTree(temp)
return root
}
//public class TreeNode {
// public var val: Int
// public var left: TreeNode?
// public var right: TreeNode?
// public init() { self.val = 0; self.left = nil; self.right = nil; }
// public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; }
// public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) {
// self.val = val
// self.left = left
// self.right = right
// }
//}