Evaluate Boolean Binary Tree
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public boolean evaluateTree(TreeNode root) {
// null 제외
if (root == null) {
return false;
}
// Base Case
if (root.val == 1) {
return true;
}
if (root.val == 0) {
return false;
}
// 재귀
if (root.val == 2) {
return evaluateTree(root.left) || evaluateTree(root.right);
}
return evaluateTree(root.left) && evaluateTree(root.right);
}
}
#99클럽 #코딩테스트 준비 #개발자 취업 #항해99 #TIL