Leetcode:symmetric Tree "Python Edition"

Source: Internet
Author: User

#error caused by:
#1: {} did not consider the none input
#2: {1,2,2} does not control H and t
#3: {4,-57,-57,#,67,67,#,#,-97,-97} does not consider the minus sign, the s from STR to list, using 9999 for empty values;

---------------------

The symmetry is verified by layer, and the asymmetry is ended;

1 #Definition for a binary tree node2 #class TreeNode:3 #def __init__ (self, x):4 #self.val = x5 #self.left = None6 #self.right = None7 8 classSolution:9     #@param root, a tree nodeTen     #@return A Boolean One     defissymmetric (self,root): ARET =True -Q = [] -s = [] the         ifRoot! = None:#Note root is empty - q.append (Root) - s.append (root.val) -          while(Len (q)! = 0 andRET = =True): +h =0 -t = Len (s)-1 +              while(H <t): A                 if(S[h]! =s[t]): atRET =False -                      Break -H+=1#I forgot to control H and t here. -T-=1 -TQ =Q -s = [] inQ = [] -              while(Len (TQ)! = 0 andRET = =True): tot = Tq.pop (0)#Pop pops up last value by default +                 ifT.left! =None: - q.append (t.left) the s.append (t.left.val) *                 Else: $S.append (9999)Panax Notoginseng                 ifT.right! =None: - q.append (t.right) the s.append (t.right.val) +                 Else: AS.append (9999) the         returnRet

Leetcode:symmetric Tree "Python Edition"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.