描述:递归

代码:

 class Solution:
# @param num, a list of integers
# @return a tree node
def sortedArrayToBST(self, num):
if len(num) == 0:
return None mid_index = len(num) / 2 tmp_tree = TreeNode(num[mid_index])
tmp_tree.left = self.sortedArrayToBST(num[:mid_index])
tmp_tree.right = self.sortedArrayToBST(num[mid_index + 1:]) return tmp_tree

#Leet Code# Convert Sorted Array to Binary Search Tree的更多相关文章

  1. [Leetcode][JAVA] Convert Sorted Array to Binary Search Tree && Convert Sorted List to Binary Search Tree

    Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...

  2. 【leetcode】Convert Sorted Array to Binary Search Tree

    Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...

  3. 【LeetCode OJ】Convert Sorted Array to Binary Search Tree

    Problem Link: http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ Same idea ...

  4. 34. Convert Sorted List to Binary Search Tree && Convert Sorted Array to Binary Search Tree

    Convert Sorted List to Binary Search Tree OJ: https://oj.leetcode.com/problems/convert-sorted-list-t ...

  5. LeetCode:Convert Sorted Array to Binary Search Tree,Convert Sorted List to Binary Search Tree

    LeetCode:Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in asce ...

  6. Convert Sorted Array to Binary Search Tree

    Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...

  7. 37. leetcode 108. Convert Sorted Array to Binary Search Tree

    108. Convert Sorted Array to Binary Search Tree 思路:利用一个有序数组构建一个平衡二叉排序树.直接递归构建,取中间的元素为根节点,然后分别构建左子树和右 ...

  8. [LeetCode] 108. Convert Sorted Array to Binary Search Tree ☆(升序数组转换成一个平衡二叉树)

    108. Convert Sorted Array to Binary Search Tree 描述 Given an array where elements are sorted in ascen ...

  9. LeetCode: Convert Sorted Array to Binary Search Tree 解题报告

    Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...

随机推荐

  1. 安装完Ubuntu 14.04要做的九件事

    www.linuxidc.com/Linux/2014-04/100411.htm 1.看看有哪些新特性 安装完之后的第一件事肯定是看看Ubuntu 14.04有哪些新的特性. Ubuntu 14.0 ...

  2. DDD的好文章

    http://www.jdon.com/44815   //cqrs 架构 http://www.jdon.com/tags/272 解道领域驱动专题

  3. careercup-递归和动态规划 9.2

    9.2 设想有个机器人坐在X*Y网格的左上角,只能向右.向下移动.机器人从(0,0)到(X,Y)有多少种走法? 进阶: 假设有些点为“禁区”,机器人不能踏足.设计一种算法,找到一条路径,让机器人从左上 ...

  4. How to Enable Multi-Touch

    This is a frequently asked question. Multi-touch feature is available on both iOS & Android port ...

  5. iOS 网络编程:NSURLSession

    NSURLSession类和相关的类提供很多API来下载HTTP的内容.这些API提供多种delegate协议来支持验证和执行后台下载任务. 1 URL Session 设计概念 Session中的任 ...

  6. docker daemonize sshd service

    # 第一个-d表示让容器在后台运行 # 末尾的-D表示启动ssh的daemon模式,不然容器启动后立刻就变为停止状态了 docker run -d NAME/VERSION /etc/init.d/s ...

  7. sea.js 学习

    开篇:终于学习了sea.js的使用了,因为它是一个模块加载工具,所以首先要了解javascript的模块编程,然后对sea.js的了解和使用 javascript 模块编程 为什么要模块化编程,为了让 ...

  8. Double跟double

    Double 是类 double是基础数据类型.Double类型是double的包装类,在JDK1.5以后,二者可以直接相互赋值,称为自动拆箱和自动装箱.看你的提示,我推测你的jdk版本在1.5以前. ...

  9. Unity3D用vistual studio打卡C#脚本卡死解决

    小黑已经跟我3年了,不仅很喜欢他方正酷黑的外表,而且稳定性绝对没的说.我已经3年没有重装过系统了,而且现在装了3个系统!虽然小黑很适合程序员,但是他最大的缺点就是做设计比较吃力,显卡512M.像uni ...

  10. JavaMail组件实现邮件功能

    实现邮件收发功能需要3个jar包: 1.JavaMail组件保内的mail.jar和smtp.jar包 2.JAF组件包里的activition.jar. 复制到WebRoot/WEB-INF/lib ...