原题题目
代码实现(首刷自解)
#define MAX 100001
#define INF 1000001bool isEvenOddTree(struct TreeNode* root){
if(!root)return false;struct TreeNode* queue[MAX],*pos = NULL;int top = -1,rear = -1,size = 0,num,prenum,level = 0;queue[++rear] = root;while(rear != top){
size = rear - top;if(!(level % 2))prenum = 0;elseprenum = INF;while(size--){
pos = queue[++top];num = pos->val;if(!(level % 2)){
if(num <= prenum || !(num % 2))return false;elseprenum = num;}else{
if(num >= prenum || num % 2 )return false;elseprenum = num;}if(pos->left) queue[++rear] = pos->left;if(pos->right) queue[++rear] = pos->right;}level++;}return true;
}