Judging whether the binary tree is mirror

?

Share a picture

Share a picture

  • 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)?{??
  • < li>????//Left??

  • ? ???if?(n.left?!=?null)?{??
  • < li>????????search(nums,?n.left,?k?+?1);?? < /li>

  • ????}??
  • ????//Node value, level??
  • ?? ??nums.push(n.val?+?‘,’?+?k);??
  • ????//Right??
  • ????if?(n.right?!= ?null)?{??
  • ????????search(nums,?n.right,?k?+?1);??
  • ????}??
  • }??

    ? ?

    From

}??

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5270 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.