vJechsmayr / PythonAlgorithms

All Algorithms implemented in Python 3 a project for hacktoberfest2020 - NO Issues or PRs for hacktoberfest 2021
MIT License
132 stars 367 forks source link

0222 - Count Complete Tree Nodes #756

Closed Ahkam95 closed 4 years ago

Ahkam95 commented 4 years ago

Description of the Problem

Given a complete binary tree, count the number of nodes.

Note:

Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, 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.

Example:

Input: 1 / \ 2 3 / \ / 4 5 6

Output: 6

Code

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def countNodes(self, root: TreeNode) -> int:

Link To The LeetCode Problem

LeetCode

Ahkam95 commented 4 years ago

I would love to do this. @vJechsmayr assign me please