Leetcode 222 Count Complete Tree Nodes

Source: Internet
Author: User

Today did a leetcode problem, just beginning is a violent crack, found special judge, very large tree, and then a meal to think, a check, found can use the nature of complete binary tree, and then use the Python to write, Found or not, (this version is to use the height of the left and right children to find, if equal so can directly get the current number of sub-tree nodes,), so continue to think, how to make use of the complete binary tree nature, thought, only need to find the leaf node, the node, is the last leaf node, and then records to find his path, through the path to get the last layer of the total number of leaves, plus the front can be considered as a lower layer of the complete binary tree, you can get the total number of nodes, but still did not, simply crazy, (although there is no further analysis of its algorithmic complexity, But can obviously find the place to reduce, then find time to do a complete analysis, and then think about whether it is the problem of the leetcode itself, the same problem of different language processing is not enough, I simply write a C + + code (long time no write, already even the seal number is quickly forgotten), and sure enough passed, Or the first version of the algorithm, after the question is to be optimistic about whether the topic is suitable for the scripting language such as Python

Leetcode 222 Count Complete Tree Nodes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.