Add implementation for leetcode problems 106, 129#1580
Conversation
Construct Binary Tree from Inorder and Postorder Traversal (leetcode_106.py)Your solution has a good approach by using a hashmap for O(1) index lookup and a global index to traverse the postorder array. However, there is a minor issue in the initial call to Also, note that the parameters Your code is efficient with O(n) time and space complexity. The use of a global index for postorder traversal is correct and efficient. You also provided two alternative implementations in comments. These are less efficient: the first one uses array slicing which creates new arrays and has O(n) time per slice, leading to O(n^2) time complexity. The second one uses To improve:
Overall, your solution is correct and efficient. With a small change for clarity, it would be excellent. VERDICT: PASS Root to Leaf Sum (leetcode_129.py)Your solution is correct in logic and follows a BFS approach, which is a valid way to solve the problem. The code is clear and well-commented, which is good practice. However, there is a performance issue with using Here's a suggested improvement for your code:
Additionally, you should consider handling the case where the root is None to avoid potential errors. Although the problem states the number of nodes is at least 1, it's good practice to check for edge cases. Overall, your solution is correct but can be optimized for time by using a more efficient data structure for the queue. VERDICT: NEEDS_IMPROVEMENT |
No description provided.