GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — EdwardLeetcode/ConvertSortedArraytoBinarySearchTree.java at master · shua2018ti/EdwardLeetcode Expand file tree/ Copy pathConvertSortedArraytoBinarySearchTree.javaMore file actions 35 lines (31 loc) · 919 Bytes / Copy pathConvertSortedArraytoBinarySearchTree.javaFile metadata and controls35 lines (31 loc) · 919 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package leetcode; /** * Project Name : Leetcode * Package Name : leetcode * File Name : ConvertSortedArraytoBinarySearchTree * Creator : Edward * Date : Sep, 2017 * Description : TODO */ public class ConvertSortedArraytoBinarySearchTree { /** * 108. Convert Sorted Array to Binary Search Tree [1,2,3,4,5] time : O(n); space : O(n); * @param nums * @return */ public TreeNode sortedArrayToBST(int[] nums) { if (nums == null || nums.length == 0) return null; return helper(nums, 0, nums.length - 1); } public TreeNode helper(int[] nums, int left, int right) { // space : O(logn); if (left > right) return null; int mid = (right - left) / 2 + left; TreeNode node = new TreeNode(nums[mid]); node.left = helper(nums, left, mid - 1); node.right = helper(nums, mid + 1, right); return node; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |