[leetcode] 814. Binary Tree Pruning

kldaji·2022년 9월 6일
0

leetcode

목록 보기
48/56

class Solution {
    fun pruneTree(root: TreeNode?): TreeNode? {
        if (root == null) return null
        
        root.left = pruneTree(root.left)
        root.right = pruneTree(root.right)
        
        if (root.left == null && root.right == null && root.`val` == 0) return null
        
        return root
    }    
}
profile
다양한 관점에서 다양한 방법으로 문제 해결을 지향하는 안드로이드 개발자 입니다.

0개의 댓글