Smallest String Starting From Leaf - Leetcode 988 - Python

9,672
0
Published 2024-04-16

All Comments (21)
  • @jessicakoch2331
    even if I solve a problem, I immediately go to see your explanation, so many of leetcode’s editorials are indecipherable (at least for me)
  • @tekfoonlim4745
    This is today's leetcode problem. Nice explanation man!
  • @MP-ny3ep
    Thank you so much. This was so beautifully explained.
  • @licokr
    Thanks for uploading the video! It motivates me. Consistency is the key! 🔑
  • @raviyadav2552
    can you make a series dedicated to trees and related concepts?
  • @daikaji3833
    Today is the day. I'm tired of sitting here with this degree and being unable to use it. No more wasted potential. I am buying the 1 yr subscription right now, and I'm going all in to prepare for job hunting. Thank you for all that you do.
  • @adityamwagh
    Hey, I think it would be a good idea to make a webextension which enables us to see this video in the leetcode tab itself!
  • @MiraKumar-rm5ke
    I have a question, for the input - [25, 1, 3, 1, 3, 0, 2] shouldn't the output be "bbz" and not "adz" (actual output). Your input is appreciated. thanks! @NeetCodeIO
  • @yusareba
    may I ask what highlighting/writing software?
  • Neetcide, I request you to please solve the concurrency problems on leetcode. The leetcode numbers are 1114, 1115, 1116, 1117, 1188, 1195, 1226, 1242, 1279.
  • @chrischika7026
    im pretty sure you dont need the if not root: return part because you never have node
  • @sankhadip_roy
    Less code but same concept class Solution: def smallestFromLeaf(self, root: Optional[TreeNode]) -> str: self.ans="{" def dfs(node, word): if not node: return word = chr(97 + node.val)+word if not node.left and not node.right: if word
  • @yang5843
    I wrote mine a little differently class Solution { String rc = ""; public String smallestFromLeaf(TreeNode root) { dfs(root,""); return rc; } void dfs(TreeNode root, String temp) { if ( root == null ) return; temp = (char) ('a'+root.val)+temp; if (root.left == null && root.right == null ) { if ( rc.equals("") || temp.compareTo(rc) < 0 ) rc = temp; return; } dfs(root.left,temp); dfs(root.right,temp); } }