标签:
/* * 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
标签:
原文地址:http://www.cnblogs.com/zmyvszk/p/5503951.html