Valid Parentheses | Leetcode - 20 | Python | Coding Interview

Поділитися
Вставка
  • Опубліковано 10 лис 2024

КОМЕНТАРІ • 10

  • @techerror8
    @techerror8  Рік тому +2

    Like 👍
    Share 📣
    Comment 💬
    Click this link to Subscribe 👉 tinyurl.com/4e2nj4vr
    Press the Bell icon🔔for updates
    Happy Learning
    Cheers

  • @Magevet32
    @Magevet32 Рік тому +1

    Hi, thank you for the explanation! I was able to follow along and understand most of these concepts. I do have one question. Could you explain the last return? I don't understand the "False if stack else True" portion. Maybe it is just late.

    • @techerror8
      @techerror8  Рік тому +3

      In Python, an empty list, tuple, or string is considered "falsy", meaning it is equivalent to False in a boolean context. Any non-empty list, tuple, or string is considered "truthy", meaning it is equivalent to True in a boolean context.
      The last return statement is using this behavior to return False if the stack is non-empty and True if the stack is empty. Here's how it works:
      stack is a list that contains any opening parentheses that have not been matched with closing parentheses.
      The expression False if stack else True is a ternary operator that returns False if stack is non-empty (i.e., "falsy") and True if stack is empty (i.e., "truthy").
      If stack is empty, the ternary operator returns True, which is equivalent to saying that all the opening parentheses have been matched with closing parentheses and the string is valid.
      If stack is non-empty, the ternary operator returns False, which is equivalent to saying that some opening parentheses have not been matched with closing parentheses and the string is invalid.
      I hope that helps! Let me know if you have any more questions. Hope this Helps :) Subscribe for more :)

  • @ayushgupta7731
    @ayushgupta7731 Рік тому +1

    Hello Tech Wired, how much time and practice did it take to be master Python?
    Any tips and tricks.

    • @techerror8
      @techerror8  Рік тому +3

      Thanks for asking. Start with the basics. Before diving into complex Python concepts, make sure to have a solid understanding of the fundamentals such as variables, data types, control flow, and functions.
      Practice, practice, practice. Consistent practice is key to mastering Python. Start by solving small programming challenges, then gradually move to more complex problems. Hope this Helps :) Subscribe for more :)

    • @ayushgupta7731
      @ayushgupta7731 Рік тому +1

      @@techerror8 Already Subscribed and thanks 😀

  • @jeffjames15
    @jeffjames15 Рік тому +1

    Beautiful

    • @techerror8
      @techerror8  Рік тому +1

      Glad it Helped :) Subscribe for more :)

  • @nejxx
    @nejxx Рік тому +1

    very nice