[SOLVED!] Lowet Common Ancestor of a Binary Tree III - LeetCode 1650 - Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ธ.ค. 2024

ความคิดเห็น • 3

  • @IOSAppCrazy
    @IOSAppCrazy 4 หลายเดือนก่อน +2

    Bro… Explain the intuition of WHY this works. Literally anyone doing leetcode can read what you wrote line by line but if people don’t understand WHY we set p -> q in the case there’s no parent, and WHY them meeting means we’ve found a LCA, then your little video just either shows us you have an awful ability to communicate or no actual understanding of why this works.
    Submitting with no explanation and going “ezpz” is nuts lmao. If someone wrote this up and didn’t explain why it works they’d get insta-rejected.
    Awful.

    • @lolitzshelly7229
      @lolitzshelly7229 3 หลายเดือนก่อน

      Agreed. Was looking for a reason why in the world do we set p1 to q or the other way around...

    • @sambitnag1154
      @sambitnag1154 หลายเดือนก่อน

      The logic actually is to make the pointers to the nodes travel an equal distance from a point until they meet and that is the LCA . say the distance between p1 and the lca node is d1, and lca to root is d2, and between p2 to lca is d3 so the distance that p1 travels is d1 -> d2 -> d3 and the distance that p2 travels is d3-> d2 -> d1 the idea is to bridge the gap which p1 and p2 takes to reach the common ancestor by altering their path. Hope this helps