Introduction
It is an easy level tree algorithm. I came out the idea to use prefix sum and also hashmap to track any path from root to leaf using O(1) time.
My practice
Here is my C# code. My code failed one test case, and then I added edge case for search value zero. I added two lines, line 46, 47.
Solution without using hashmap
I did study one of solutions in discussion panel. I have to think and learn to write one solution without using hashmap. But the time complexity is less optimal, O(N2), N is total nodes in the tree.
Leetcode discussion panel
I like to build a new habit to share my learning on leetcode discussion panel. Here is my sharing.
No comments:
Post a Comment