Counting nodes in a tree in Java

前端 未结 15 1671
我寻月下人不归
我寻月下人不归 2020-12-03 00:03

First of all, I swear this is not homework, it\'s a question I was asked in an interview. I think I made a mess of it (though I did realise the solution requires recursion).

15条回答
  •  自闭症患者
    2020-12-03 00:25

    Implement the method:

    public static int countOneChild(Node root)
    {
        ...
    }
    

    that counts the number of internal nodes in a binary tree having one child. Add the function to tree.java program.

提交回复
热议问题