Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): L = [] R = [] def getLChilds(self, root): if not root: self.L.append('#') return self.L.append(root.val) self.getLChilds(root.right) self.getLChilds(root.left) def getRChilds(self, root): if not root: self.R.append('#') return self.R.append(root.val) self.getRChilds(root.right) self.getRChilds(root.left) def isSameTree(self, p, q): """ :type p: TreeNode :type q: TreeNode :rtype: bool """ self.L = [] self.R = [] if not p and not q: return True if not p and q: return False if p and not q: return False self.getLChilds(p) self.getRChilds(q) if self.L == self.R: return True else: return False
相关推荐
Queues, on the other hand, operate on a First-In-First-Out (FIFO) basis. Items are added at the end (enqueue) and removed from the front (dequeue). Queues are employed in tasks like job scheduling, ...
(5)Understand different search strategies, such as: the Breadth-first search(BFS) ,the Depth-first search(DFS) and the Best-first search(BFS) Search strategies etc., and compare the difference of ...
* [Depth-First Search](https://github.com/kamyu104/LeetCode#depth-first-search) * [Backtracking](https://github.com/kamyu104/LeetCode#backtracking) * [Dynamic Programming]...
same PBtree structure if and only if the two sets have the same number of data items) and node indistinguishability (i.e., the values of PBtree nodes are completely random and have no statistical ...
Because the trees are balanced, finding any record requires about the same amount of resources, and retrieval speed is consistent because the index has the same depth throughout. Clustered and ...
Tree Map Chart Type - Another chart type requested by Dundas customers, the innovative Tree Map custom chart type shows any two metrics at once, using both size and color. Think of it as a "heat map ...
RecordName,IP,Port,User,Password,Domain,ColorDepth,Updates,UnlockDesktop,Fullscreen,Nofullkbcontrol,Monitor,Sendrequest,Pbpath,Proxy,AsProxyBy,Memory,TreePath sample01,192.168.0.6,4899,user01,,,,,,,...
upsearch until a device scope is found before executing _ADR. This allows PCI_Config operation regions to be declared locally within control methods underneath PCI device objects. Fixed a problem ...
RecordName,IP,Port,User,Password,Domain,ColorDepth,Updates,UnlockDesktop,Fullscreen,Nofullkbcontrol,Monitor,Sendrequest,Pbpath,Proxy,AsProxyBy,Memory,TreePath sample01,192.168.0.6,4899,user01,,,,,,,...
To guarantee uniqueness, they should be based on the full path in a project's source tree. For example, the file foo/src/bar/baz.h in project foo should have the following guard: #ifndef FOO_BAR_BAZ...
Basically, the code does the same things that Koza & Rice s simple LISP does and is set up to handle multiple populations as well (e.g., for co-evolution). You need to provide three modules, setup.c...
Once he surf the seas, and now sleeps on the depth and has dreams of waves and wind, blow it sails. Crystal Fireplace 3D Screensaver v1.0 build 5 Find yourself in a mysterious dwelling gnomes! ...
You can easily retrieve or change the screen resolution and color depth, play audio CDs and standard wave files <END><br>44 , fsocontrol.zip This demonstration version of this control is a wrapper...