Skip to content

Commit 1a625a8

Browse files
committed
feat: Add solution for LeetCode problem 226
1 parent 9688594 commit 1a625a8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

invert-binary-tree/WhiteHyun.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// 226. Invert Binary Tree.swift
3+
// https://leetcode.com/problems/invert-binary-tree/description/
4+
// Algorithm
5+
//
6+
// Created by 홍승현 on 2024/05/04.
7+
//
8+
9+
import Foundation
10+
11+
final class LeetCode226 {
12+
func invertTree(_ node: TreeNode?) -> TreeNode? {
13+
guard let node else { return nil }
14+
15+
let left = node.left
16+
let right = node.right
17+
18+
node.left = invertTree(right)
19+
node.right = invertTree(left)
20+
21+
return node
22+
}
23+
}

0 commit comments

Comments
 (0)