Path Sum - Leetcode 112 - Trees (Python)

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • Master Data Structures & Algorithms for FREE at AlgoMap.io/
    Code solutions in Python, Java, C++ and JS for this can be found at my GitHub repo here: github.com/gah...
    Complete DSA Pathway Zero to Hero: • Data Structures & Algo...
    Please check my playlists for free DSA problem solutions:
    • Fundamental DSA Theory
    • Array & String Questions
    • 2 Pointers Questions
    • Sliding Window Questions
    • Binary Search Questions
    • Stack Questions
    • Linked List Questions
    • Tree Questions
    • Heap Questions
    • Recursive Backtracking...
    • Graph Questions
    • Dynamic Programming (D...
    My Data Science & ML RUclips Playlist: • Greg's Path to Become ...
    Learn Python and Data Science FASTER at mlnow.ai :)
    Support the content: / @greghogg
    Follow me on Instagram: / greghogg5
    Connect with me on LinkedIn: / greghogg
    Follow me on TikTok: / greghogg5
    Coursera Plus: imp.i384100.ne...
    My Favorite Courses:
    Data Structures & Algorithms:
    - UCalifornia San Diego DSA: imp.i384100.ne...
    - Stanford Algorithms: imp.i384100.ne...
    - Python Data Structures: imp.i384100.ne...
    - Meta Coding Interview Prep: imp.i384100.ne...
    Python:
    - UMichigan Python for Everybody: imp.i384100.ne...
    - Python Mastery from MLNOW.ai: mlnow.ai/cours...
    - Google IT Automation w/ Python: imp.i384100.ne...
    Web Dev / Full Stack:
    - Meta Front-End Developer: imp.i384100.ne...
    - IBM Full Stack Developer: imp.i384100.ne...
    - Meta Back-End Developer: imp.i384100.ne...
    - John Hopkins HTML, CSS & JS: imp.i384100.ne...
    - IBM DevOps: imp.i384100.ne...
    Cloud Development:
    - AWS Fundamentals: imp.i384100.ne...
    - GCP Cloud Engineer: imp.i384100.ne...
    - Microsoft Azure Fundamentals: imp.i384100.ne...
    Game Development:
    - Michigan State Unity Development: imp.i384100.ne...
    - UColorado C++ for Unreal Engine: www.coursera.o...
    SQL & Data Science:
    - SQL by MLNOW.ai: mlnow.ai/cours...
    - Python for Data Science by MLNOW.ai: mlnow.ai/cours...
    - Google Data Analytics: imp.i384100.ne...
    - IBM Data Science: imp.i384100.ne...
    - IBM Data Engineer: imp.i384100.ne...
    Machine Learning & AI:
    - ML Mastery at MLNOW.ai: mlnow.ai/cours...
    - ML w/ Andrew Ng: www.coursera.o...
    - Deep Learning w/ Andrew Ng: imp.i384100.ne...

Комментарии • 8

  • @GregHogg
    @GregHogg  2 месяца назад

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @xingyuxiang1637
    @xingyuxiang1637 3 месяца назад

    In my opinion, leaf node checking can also prevent passing null to the function call. So, target_sum - root.val follows the flow of the program.

  • @arsheyajain7055
    @arsheyajain7055 3 месяца назад

    Awesome

  • @asagiai4965
    @asagiai4965 3 месяца назад

    Nice, explanation and presentation.
    Though I think the question here. ( questions to the leetcode not your code)
    1.) I wonder why they didn't give some kind of a sorted binary tree?
    2.) What if you already get the target before you reach the leaf? So I guess still return True?

    • @aakashs1806
      @aakashs1806 3 месяца назад +1

      Binary trees need not be in sorted fashion.
      Also the question is path sum. Path might be defined as start node to leaf.

    • @asagiai4965
      @asagiai4965 3 месяца назад

      @@aakashs1806 well true, though it is good for a binary tree to be sorted. But it is what it is.
      Well if path if defined like that then you are correct, but if path is defined in a graph.
      You don't need to be on the end node to call it a path.

    • @michaurbanski5961
      @michaurbanski5961 3 месяца назад +1

      ​@@asagiai4965 It states in the problem description that the path must be root-leaf :)

    • @asagiai4965
      @asagiai4965 3 месяца назад

      @@michaurbanski5961 i see