Wednesday, December 19, 2018

958. Check Completeness of a Binary Tree

Dec. 19, 2018

Introduction


It is one of algorithms in weekly contest 115. I learned a new idea to solve the algorithm today.

A new idea 


It is so busy recently but I had chance to explore the idea I saw in the coding blog from Linkedin.com sharing post. Here is the link.

I wrote a comment after I learned the idea, and I did some minor change. Here is my comment.

Thank you for sharing. 

Your solution will be perfect one since it is much easy to write compared to my solution written in last week Leetcode contest 115.

But I played with different ideas based on your approach, and the map using size N = 100 is very challenging one. I came cross the index out of range error. I did not fully understand the given condition of 100 nodes at most in the tree, if it is a complete tree, then map should be fit into 101. Otherwise, the size can be 1 + 2 + ...+ 2^100. 
I spent time to learn your idea and play with different approach. None of them works and I could not make any improvement, so I tried to make a minor change to entertain the hard work and things I learned. 


I chose not to use map instead, I choose to use two variables to help me track, count of nodes in the tree and sum of index. The code passed Leetcode online judge. You give us a lot of inspiration I am talking from weekly contest players viewpoints. 

Leetcode discuss link is here.

No comments:

Post a Comment