C# Solution


  • 0
           public int FindBottomLeftValue(TreeNode root) {
                TreeNode mostLeftNode = null, currentNode = null;
                Queue<TreeNode> level = new Queue<TreeNode>();
                int currentLevelCount = 0;
    
                level.Enqueue(root);
                
                while(level.Count != 0)
                {
                    currentLevelCount = level.Count;
                    mostLeftNode = level.Peek();
    
                    do
                    {
                        currentNode = level.Dequeue();
    
                        if (currentNode.left != null)
                            level.Enqueue(currentNode.left);
                        if (currentNode.right != null)
                            level.Enqueue(currentNode.right);
                    }
                    while (--currentLevelCount > 0);
                }
    
                return mostLeftNode.val;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.