231.2的幂
if(n<=0):return false
else if((n&n-1)==0):return true
else return false
235.二叉搜索树的最近公共祖先
class Solution(object):
def lowestCommonAncestor(self, root, p, q):
"""
:type root: TreeNode
:type p: TreeNode
:type q: TreeNode
:rtype: TreeNode
"""
if p.val<root.val and q.val<root.val:
return self.lowestCommonAncestor(root.left,p,q)
if p.val>root.val and q.val>root.val:
return self.lowestCommonAncestor(root.right,p,q)
return root
236.二叉树的最近公共祖先
class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
if root in (None ,p,q):
return root
L = self.lowestCommonAncestor(root.left,p,q)
R =self.lowestCommonAncestor(root.right,p,q)
return R if None==L else L if None==R else root