From 58b2a01527a50f93f4d0ee82230b8d8229d9aa41 Mon Sep 17 00:00:00 2001 From: aakashdeshamne <21512493.dypit@dypvp.edu.in> Date: Mon, 9 Oct 2023 19:16:29 +0530 Subject: [PATCH 1/3] Added solution for python --- Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py diff --git a/Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py b/Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py new file mode 100644 index 0000000..e69de29 From 1f0ef8f5cd59bf55052db28e21bb60b2feeed9b1 Mon Sep 17 00:00:00 2001 From: aakashdeshamne <127671909+aakashdeshamne@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:26:50 +0530 Subject: [PATCH 2/3] Update Solution.py --- .../Solution.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py b/Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py index e69de29..50d682e 100644 --- a/Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py +++ b/Easy/108. Convert Sorted Array to Binary Search Tree/Solution.py @@ -0,0 +1,22 @@ +class TreeNode: + def __init__(self, val=0, left=None, right=None): + self.val = val + self.left = left + self.right = right + +class Solution: + def sortedArrayToBST(self, nums): + if not nums: + return None + head = self.helper(nums, 0, len(nums) - 1) + return head + + def helper(self, nums, low, high): + if low > high: + return None + mid = low + (high - low) // 2 + node = TreeNode(nums[mid]) + node.left = self.helper(nums, low, mid - 1) + node.right = self.helper(nums, mid + 1, high) + return node + From 95ed1b92ee3d695baf6a865c5cdf084d3fd66e75 Mon Sep 17 00:00:00 2001 From: aakashdeshamne <127671909+aakashdeshamne@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:27:29 +0530 Subject: [PATCH 3/3] Update Solution.py