def isPowerOfFour(self, num):
return bool(re.match(r'^0b1(00)*$',bin(num)))
J
Johnny_Wang
@Johnny_Wang
0
Reputation
4
Posts
48
Profile views
0
Followers
0
Following
Posts made by Johnny_Wang

One line solution in Python using re.match

RE: VERY SIMPLE Python solutions (iterative and recursive), both beat 90%
@nmbmlyx0211 Once the left subtree or right subtree is unbalance(the hight difference larger than 1), the corresponding value will be 1.

Python Recursive Solution
class Solution(object):
def isSymmetric(self, root): if root is None: return True else: return self.compare(root.left,root.right) def compare(self,l,r): if l and r: return l.val == r.val and self.compare(l.left,r.right) and self.compare(l.right,r.left) else: return l is r