[LeetCode][Python3] 108. Convert Sorted Array to Binary Search Tree
2018. 11. 6. 00:19 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
My Solution :
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def sortedArrayToBST(self, nums):
"""
:type nums: List[int]
:rtype: TreeNode
"""
if nums:
mid = len(nums)//2
node = TreeNode(nums[mid])
node.left = self.sortedArrayToBST(nums[:mid])
node.right = self.sortedArrayToBST(nums[mid+1:])
return node
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 22. Generate Parentheses (0) | 2018.11.10 |
---|---|
[LeetCode][Python3] 19. Remove Nth Node From End of List (0) | 2018.11.09 |
[LeetCode][Python3] 17. Letter Combinations of a Phone Number (0) | 2018.11.09 |
[LeetCode][Python3] 11. Container With Most Water (0) | 2018.11.07 |
[LeetCode][Python3] 387. First Unique Character in a String (0) | 2018.11.05 |
[LeetCode][Python3] 350. Intersection of Two Arrays II (0) | 2018.11.05 |
[LeetCode][Python3] 344. Reverse String (0) | 2018.11.05 |
[LeetCode][Python3] 268. Missing Number (0) | 2018.11.04 |
최근에 달린 댓글 최근에 달린 댓글