⭐ 코딩테스트/Codility

[Codility] Tree Height

Designerd 2024. 2. 18. 15:25

 

[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