I was trying to use level order traversal & greedy to solve this problem, calculate the sum of the node values in the even levels of the tree and the sum of the node values in the odd levels of the tree, then return the maximum of these two number.

But I can't pass the test, could anyone please give me some hints about where goes wrong? Thank you so much!

```
public int rob(TreeNode root) {
if(root == null){
return 0;
}
int odd_level = 0;
int even_level = 0;
boolean flag = true;
Queue<TreeNode> q = new LinkedList<TreeNode>();
q.add(root);
while(! q.isEmpty()){
int num_of_level = q.size();
for(int i = 0; i < num_of_level; i ++){
if(q.peek().left != null){
q.add(q.peek().left);
}
if(q.peek().right != null){
q.add(q.peek().right);
}
if(flag){
odd_level += q.poll().val;
}else{
even_level += q.poll().val;
}
}
if(flag){
flag = false;
}else{
flag = true;
}
}
return odd_level > even_level ? odd_level : even_level;
}
```