File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ class Solution {
251251 return root;
252252 }
253253}
254- ```
254+ ```
255255
256256迭代: 左闭右闭 [ left,right]
257257``` java
@@ -373,7 +373,24 @@ var sortedArrayToBST = function (nums) {
373373};
374374```
375375
376+ ## TypeScript
377+
378+ ``` typescript
379+ function sortedArrayToBST(nums : number []): TreeNode | null {
380+ function recur(nums : number [], left : number , right : number ): TreeNode | null {
381+ if (left > right ) return null ;
382+ let mid: number = Math .floor ((left + right ) / 2 );
383+ const root: TreeNode = new TreeNode (nums [mid ]);
384+ root .left = recur (nums , left , mid - 1 );
385+ root .right = recur (nums , mid + 1 , right );
386+ return root ;
387+ }
388+ return recur (nums , 0 , nums .length - 1 );
389+ };
390+ ```
391+
376392## C
393+
377394递归
378395``` c
379396struct TreeNode* traversal (int* nums, int left, int right) {
You can’t perform that action at this time.
0 commit comments