108. Convert Sorted Array to Binary Search Tree
Posted 我的名字叫周周
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了108. Convert Sorted Array to Binary Search Tree相关的知识,希望对你有一定的参考价值。
/* * 108. Convert Sorted Array to Binary Search Tree * 2016-5-17 By Mingyang */ public TreeNode sortedArrayToBST(int[] num) { if (num.length == 0) return null; return sortedArrayToBST(num, 0, num.length - 1); } public TreeNode sortedArrayToBST(int[] num, int start, int end) { if (start > end) return null; int mid = (start + end) / 2; TreeNode root = new TreeNode(num[mid]); root.left = sortedArrayToBST(num, start, mid - 1); root.right = sortedArrayToBST(num, mid + 1, end); return root; }
以上是关于108. Convert Sorted Array to Binary Search Tree的主要内容,如果未能解决你的问题,请参考以下文章
108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree
leetcode 108 Convert Sorted Array to Binary Search Tree