108. Convert Sorted Array to Binary Search Tree - Easy 前往題目 想法 也是很久以前做過的題目了,但完全忘了怎麼寫 思路 binary search就可以建構出這個tree Codeclass Solution { public TreeNode sortedArrayToBST(int[] nums) { return createTree(nums, 0, nums.length - 1); } private TreeNode createTree(int[] nums, int l, int r) { if (l > r) return null; int mid = l + (r - l) / 2; TreeNode res = new TreeNode(nums[mid]); res.left = createTree(nums, l, mid - 1); res.right = createTree(nums, mid + 1, r); return res; } } 2024/10/17 忘了怎麼找要插入的數:D Leetcode > Medium #Leetcode #心得 #Binary Search Tree #Binary Tree #Array #Tree #Divide and Conquer 108. Convert Sorted Array to Binary Search Tree - Easy https://f88083.github.io/2024/01/19/108-Convert-Sorted-Array-to-Binary-Search-Tree-Easy/ 作者 Simon Lai 發布於 2024年1月19日 許可協議 190. Reverse Bits - Easy 上一篇 9. Palindrome Number - Easy 下一篇 Please enable JavaScript to view the comments