[Codility] Tree Height

 

 


해결전략

 

이진트리 Binary Tree


 

정답코드

 

#include <algorithm>

int answer;

void DFS(tree* node, int currLength)
{
    if(node == nullptr) return;

    answer = max(answer, currLength);

    if(node->l != nullptr){
        DFS(node->l, currLength + 1);
    }
    if(node->r != nullptr){
        DFS(node->r, currLength + 1);
    }
}

int solution(tree* T) {

    DFS(T, 0);

    return answer;
}

 

 

유사문제

 

2024.02.18 - [⭐ 코딩테스트/Codility] - [Codility] Tree Longest Zigzag

 


 

'⭐ 코딩테스트 > Codility' 카테고리의 다른 글

[Codility] Binary Gap  (0) 2024.02.18
[Codility] Array Inversion Count  (0) 2024.02.18
[Codility] Tree Longest Zigzag  (0) 2024.02.18
[Codility] The Matrix  (0) 2024.02.17
[Codility] FirstUnique  (0) 2024.02.07