안녕하세요. I think the code above should not be accepted, given the example you have provided. It is updating the hight of nodes 1 and 3 (in line 21) before updating the height of their parent, node 2, which still has a default value of -1. I have sent another code with output
2
1
2
0
1
2
and was considered correct too.
So I think your understanding of the problem is correct and the code above shouldn't pass.

tkddus0421 3년 전
아래의 코드는 현재 문제에서 정답으로 처리되는 코드입니다.
하지만 예를 들어, 아래의 binary tree를 생각해보면,
4
/ \
2 5
/ \ \
1 3 6
이 문제에서
- input
6
2
4
2
-1
4
5
- output
2
1
2
0
1
2
가 나와야하는 것을 볼 수 있는데,
아래의 코드를 실행하면,
0
1
0
0
1
2
가 출력되는 것을 확인할 수 있습니다.
제가 문제를 잘 못 이해한 것인지, data set 을 더 추가해야하는 것인지 헷갈리는 부분이 있어서 글을 남겨봅니다.