C++

/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param A: A sorted (increasing order) array
* @return: A tree node
*/
TreeNode *sortedArrayToBST(vector<int> &A) {
// write your code here
if ( == A.size()) {
return NULL;
}
return buildTree(A, , A.size()-);
}
TreeNode *buildTree(vector<int> &A, int from, int to) {
if (from > to) {
return NULL;
}
int mid = (from+to)/;
TreeNode *node = new TreeNode(A[mid]);
node->left = buildTree(A, from, mid-);
node->right = buildTree(A, mid+, to);
return node;
}
};

LintCode: Convert Sorted Array to Binary Search Tree With Minimal Height的更多相关文章

  1. 177. Convert Sorted Array to Binary Search Tree With Minimal Height【LintCode by java】

    Description Given a sorted (increasing order) array, Convert it to create a binary tree with minimal ...

  2. 【Lintcode】177.Convert Sorted Array to Binary Search Tree With Minimal Height

    题目: Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. ...

  3. Convert Sorted Array to Binary Search Tree With Minimal Height

    Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height. Exa ...

  4. Lintcode177-Convert Sorted Array to Binary Search Tree With Minimal Height-Easy

    177. Convert Sorted Array to Binary Search Tree With Minimal Height Given a sorted (increasing order ...

  5. [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 ...

  6. 【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 ...

  7. 【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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. ASP.NET Web API实践系列02,在MVC4下的一个实例, 包含EF Code First,依赖注入, Bootstrap等

    本篇体验在MVC4下,实现一个对Book信息的管理,包括增删查等,用到了EF Code First, 使用Unity进行依赖注入,前端使用Bootstrap美化.先上最终效果: →创建一个MVC4项目 ...

  2. ios6sdk 和ios7sdk 分别在ios6设备和ios7设备上的效果 对比

  3. ASP.NET MVC:Form Authentication 相关的学习资源

    看完此图就懂了 看完下面文章必须精通 Form authentication and authorization in ASP.NET Explained: Forms Authentication ...

  4. JQuery攻略(四)事件

    jQuery事件处理,鼠标的单击,双击,悬停,键盘按键,文本动画..... 此章节有 1.1被点击的按钮查找 1.2事件的自动触发 1.3点击之后禁用按钮 1.4鼠标事件 1.5焦点事件 1.6CSS ...

  5. cocos2d-x 保持屏幕点亮及自动变灰

    很早之前遇到的问题,现在记录一下.有一家Android渠道(抱歉,时间太长了已经记不大清楚是哪一家了 oppo/联想/酷派?)在我们提交新版本时拒绝了,理由是:手机背光状态下,屏幕不会自动变灰. 这里 ...

  6. IE9版本以下ajax 跨域问题解决

    ajax跨域请求数据在谷歌火狐我本地IE11都是没问题的. 让测试就发现问题了,IE8下请求不到数据,然后我查看一下自己写的js看有没有不兼容问题,可是都没有啊,为什么就请求不到呢. 我把ajax的e ...

  7. 样条之Akima光滑插值函数

    核心代码: ////////////////////////////////////////////////////////////////////// // Akima光滑插值 // t - 存放指 ...

  8. 【虚拟化实战】Cluster设计之一资源池

    作者:范军 (Frank Fan) 新浪微博:@frankfan7 资源池是Cluster设计中的一个重要概念,本文介绍了为什么用资源池,怎么用好资源池,以及澄清了一些常见的误区. 一概念 每个ESX ...

  9. GROUP BY中ROLLUP/CUBE/GROUPING/GROUPING SETS使用示例

    oracle group by中rollup和cube的区别: Oracle的GROUP BY语句除了最基本的语法外,还支持ROLLUP和CUBE语句.CUBE ROLLUP 是用于统计数据的. 实验 ...

  10. tensorflow 之tf.nn.depthwise_conv2d and separable_conv2d实现及原理

    Depthwise Separable Convolution 1.简介 Depthwise Separable Convolution 是谷歌公司于2017年的CVPR中在论文”Xception: ...