Coding Interview Tutorial 116 - Iterative Sum of Left Leaves [LeetCode]

preview_player
Показать описание
Learn how to find the sum of left leaves in a binary tree using iteration!

Algorithms, data structures, and coding interviews simplified!

Improve your coding skills, and ace the coding interview!

This is an important programming interview question, and we use the LeetCode platform to solve this problem.

Рекомендации по теме
Комментарии
Автор

There is another way that we don't check null values in lines 21 and 23 and have a null check while we are pulling from the queue. This was the problem I faced on the Island problem I was checking if the pairs are valid and then pushing to the queue.
Which makes me write code multiple times.
Does this thing matter in the interviews?

while queue:
x = queue.pop()
if not x: continue
if x.left and not x.left.left and not x.left.right:
res += x.left.val
queue.extend([x.left, x.right])

nitishsainani
welcome to shbcf.ru