【LeetCode with Python】 Convert Sorted Array to Binary Search Tree
来源:互联网 发布:电脑照相机软件下载 编辑:程序博客网 时间:2024/05/01 11:52
博客域名:http://www.xnerv.wang
原题页面:https://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
题目类型:
难度评价:★
本文地址:http://blog.csdn.net/nerv3x3/article/details/39453279
原题页面:https://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
题目类型:
难度评价:★
本文地址:http://blog.csdn.net/nerv3x3/article/details/39453279
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
class Solution: def doSortedArrayToBST(self, num, start, end): if start > end: return None mid = start + (end - start) / 2 root = TreeNode(num[mid]) root.left = self.doSortedArrayToBST(num, start, mid - 1) root.right = self.doSortedArrayToBST(num, mid + 1, end) return root # @param num, a list of integers # @return a tree node def sortedArrayToBST(self, num): len_num = len(num) if 0 == len_num: return None return self.doSortedArrayToBST(num, 0, len_num - 1)
0 0
- 【LeetCode with Python】 Convert Sorted Array to Binary Search Tree
- Leetcode -- Python -- Convert Sorted Array to Binary Search Tree
- 108. Convert Sorted Array to Binary Search Tree Leetcode Python
- [leetcode: Python] 108. Convert Sorted Array to Binary Search Tree
- 【Leetcode】【python】Convert Sorted Array to Binary Search Tree
- 【LeetCode】Convert Sorted Array to Binary Search Tree && Convert Sorted List to Binary Search Tree
- 【LeetCode】convert-sorted-link-to-binary-search-tree & convert-sorted-array-to-binary-search-tree
- Leetcode - Tree - Convert Sorted Array to Binary Search Tree
- *(leetcode) Convert Sorted Array to Binary Search Tree (tree)
- LeetCode[Tree]: Convert Sorted Array to Binary Search Tree
- LeetCode: Convert Sorted Array to Binary Search Tree
- [LeetCode]Convert Sorted Array to Binary Search Tree
- LeetCode Convert Sorted Array to Binary Search Tree
- [Leetcode] Convert Sorted Array to Binary Search Tree
- leetcode 11: Convert Sorted Array to Binary Search Tree
- Leetcode: Convert Sorted Array to Binary Search Tree
- [LeetCode] Convert Sorted Array to Binary Search Tree
- Leetcode 108 Convert Sorted Array to Binary Search Tree
- 神奇的sh:管道操作|原理 ,实现一个支持管道操作的grep
- StringBuilder 与 StringBuffer 区别
- 【LeetCode with Python】 Combinations
- Directx10 龙书笔记- 雾效的实现
- MariaDB Galera Cluster 5.5.39 on Centos 5.8_64
- 【LeetCode with Python】 Convert Sorted Array to Binary Search Tree
- 【LeetCode with Python】 Copy List with Random Pointer
- 位域之我见
- 【LeetCode with Python】 Count and Say
- 《炉石传说》架构设计赏析(3):Gameplay初探
- 【LeetCode with Python】 Divide Two Integers
- Android SDK目录详解
- 使用Firebug对js进行断点调试的图文方法
- 【LeetCode with Python】 Flatten Binary Tree to Linked List