# Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: # @param num, a list of integers # @return a tree node def sortedArrayToBST(self, num): n=len(num) if n==0: return None mid=n//2 root=TreeNode(num[mid]) root.left=self.sortedArrayToBST(num[:mid]) root.right=self.sortedArrayToBST(num[mid+1:]) return root
Sunday, September 7, 2014
Leetcode: Convert Sorted Array to Binary Search Tree @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment