if difference between parent and child is equal to 1 then do continue otherwise make flag = 0 and break
if ( Math . Abs ( temp . right . val - temp . val ) == 1 ) Q . Enqueue ( temp . right ) ; else { flag = 0 ; break ; } } } if ( flag != 0 ) return true ; else return false ; }