DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›