?
- var?isSymmetric?=?function?(root)?{??
- ????if?(root?==?null strong>)?{??
- ????????return?true;??
- ????}??
- ? ???//Left, middle and right order recursive binary tree??
- ????var ?nums?=?[];??
- ????search(nums,?root,?1);??
- ????//Determine whether it is symmetrical??
- ????var?i?=?0,?j?=?nums.length?-?1;?? < /span>
- ????while?(i?
- ?????? ??if?(nums[i]?!=?nums[j])?{??
- ??????? ?????return?false ;??
- ????????}??
- ????????i++;??
- ????????j–;??
- ????}??
- ????return?true;?? < /li>
- };??
- /**? < /span>
- ?*? Recursive binary tree according to the left, middle and right order, Output to the array nums?
- ?*[email protected]?nums?????? output?
- ?*[email protected]?n????????? node ?
- ?*[emailprotected]?k????????? level?
- ?*/??
- function ?search(nums,?n,?k)?{??
- ? ???if?(n.left?!=?null)?{??
- ????}??
- ????//Node value, level??
- ?? ??nums.push(n.val?+?‘,’?+?k);??
- ????//Right??
- ????if?(n.right?!= ?null)?{??
- ????????search(nums,?n.right,?k?+?1);??
- ????}??
-
}??
? ?
From
< li>????//Left??
< li>????????search(nums,?n.left,?k?+?1);?? < /li>
}??