DEV Community

Joao Carlos Sousa do Vale
Joao Carlos Sousa do Vale

Posted on

Technical Interview - Code #006 - LeetCode #814. Binary Tree Pruning

Level

Medium

Complexidade

Linear

Topicos

Arvores Binarias, Travessia Pre-Ordem

Problema

Dada a raiz de uma árvore binária, devolva a mesma árvore onde cada sub-árvore (da árvore dada) que não contenha um 1 foi removida.

Restrições:

O número de nós na árvore está na faixa [1, 200].
O nó.val ou é 0 ou 1.

Exemplo

 

Example 1:

Input: root = [1,null,0,0,1]
Output: [1,null,0,null,1]

Example 2:

Input: root = [1,0,1,0,0,0,1]
Output: [1,null,1,null,1]

Example 3:

Input: root = [1,1,0,1,1,0,1,0]
Output: [1,1,0,1,1,null,1]

Implementar

class Solution {
    public TreeNode pruneTree(TreeNode root) {

    }
}
Enter fullscreen mode Exit fullscreen mode

Fonte

LeetCode #814. Binary Tree Pruning
https://leetcode.com/problems/binary-tree-pruning/

LinkedIn

https://www.linkedin.com/in/joaocarlosvale/

GitHub

https://github.com/jcarlosvale/playground/blob/master/src/main/java/tests/leetcode/challenge30days/september2022/BinaryTreePruning.java

Oldest comments (0)