educative.io

Height of BST Iterative solution

Is this a valid solution? It passed all test cases on the educative editor
` public static int findHeight(Node root) {

    int rightHeight =0;
    int leftHeight =0;

    Node left =root;
    Node right = root;
    while(left.getRightChild()!=null || left.getLeftChild()!=null){

        if(left.getLeftChild()!=null){
            left = left.getLeftChild();
            leftHeight++;
        }
        else{
            left=left.getRightChild();
            leftHeight++;
        }

    }

    while( right.getLeftChild()!=null || right.getRightChild()!=null){

        if(right.getRightChild()!=null){
            right=right.getRightChild();
            rightHeight++;
        }
        else{
            right=right.getLeftChild();
            rightHeight++;
        }


}
    // Write - Your - Code
    return Math.max(rightHeight,leftHeight);
}`