Блог пользователя _Spongey

Автор _Spongey, история, 3 года назад, По-английски

Hey guys, So for this problem, my approach was to like assign every node in the tree a value, which is how long or deep is it. (IDK what it's called but basically if we had a graph: 1 --> 2, 1 --> 3, 2 --> 4. Then the height of 1 is 2, height of 2 is 1, height of 3 and 4 is zero) My code failed on test 2, 25th test. So I was wondering what am I doing wrong (If it got me TLE I was planning to dp the height and just add 1 to it) 240029463 Here's my submission, and also this submission too 240023658

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

How did you assign height to nodes? In the example you gave, nodes 1 and 2 appear symmetrically the same, so why do they have different heights? (Moreover, your solution is $$$O(n^2)$$$ so it will throw a TLE)