Zum Hauptinhalt springen
Windows Tipps & SecurityBackforce One Plus: Der ergonomische Gaming-Stuhl der HMX 6(18.09.2026 um 10:25 Uhr)
Windows Tipps & SecurityDEAN: Darum bekommt bald jeder Bundesbürger eine zweite Kontonummer(18.09.2026 um 10:25 Uhr)
Windows Tipps & SecurityBackforce One Plus: Der ergonomische Gaming-Stuhl der HMX 6(18.09.2026 um 10:25 Uhr)
Windows Tipps & SecurityDEAN: Darum bekommt bald jeder Bundesbürger eine zweite Kontonummer(18.09.2026 um 10:25 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

LeetCode Day 13 Binary Tree Part 3

LeetCode No. 104. Maximum Depth of Binary Tree

Given the root of a binary tree, return its maximum depth.

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

LeetCode No. 257. Binary Tree Paths

Given the root of a binary tree, return all root-to-leaf paths in any order.

A leaf is a node with no children.

    public List<String> binaryTreePaths(TreeNode root) {
        List<String> list = new ArrayList<>();
        if(root==null){
            return list;
        }
        String str = "";
        pathRecord(root,str,list);
        return list;
    }

    public void pathRecord(TreeNode cur, String str, List<String> result){
        str += cur.val;
        if(cur.left==null && cur.right == null){
            result.add(str);
        }else if(cur.left !=null && cur.right!=null){
            pathRecord(cur.left, str+"->", result);
            pathRecord(cur.right, str+"->", result);
        }
        else if(cur.left != null){
            pathRecord(cur.left, str+"->", result);
        }
        else{
            pathRecord(cur.right, str+"->", result);
        }


    }

LeetCode No. 222. Count Complete Tree Nodes

Given the root of a complete binary tree, return the number of the nodes in the tree.

According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

Design an algorithm that runs in less than O(n) time complexity.

Example 1:
Image description

Input: root = [1,2,3,4,5,6]
Output: 6

Example 2:

Input: root = []
Output: 0

Example 3:

Input: root = [1]
Output: 1

    public int countNodes(TreeNode root) {
        if(root==null){
            return 0;
        }
        return 1+countNodes(root.left)+countNodes(root.right);
    }

LeetCode 404. Sum of Left Leaves

Given the root of a binary tree, return the sum of all left leaves.

A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.

Example 1:

Image description
Input: root = [3,9,20,null,null,15,7]
Output: 24
Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.

Example 2:

Input: root = [1]
Output: 0

Constraints:

The number of nodes in the tree is in the range [1, 1000].
-1000 <= Node.val <= 1000

Original Page

    public int sumOfLeftLeaves(TreeNode root) {
        if(root == null){
            return 0;
        }
        return leftLeaves(root, false);

    }

    public int leftLeaves(TreeNode cur, boolean isLeft){
        if(cur == null){
            return 0;
        }
        if(cur.left == null && cur.right == null && isLeft){
            return cur.val;
        }
        return leftLeaves(cur.left, true) + leftLeaves(cur.right, false);
    }
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten LeetCode Day 13 Binary Tree Part 3

Thematisch verwandte Begriffe: LeetCode, Binary, Tree, Part · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-61591 | djust provides Phoenix LiveView-style reactive server-side rendering for…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
News ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

↗ Original-Quelle