diff --git "a/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" "b/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" index 2a88f195ba..26394eaaab 100644 --- "a/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" +++ "b/problems/0669.\344\277\256\345\211\252\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" @@ -315,6 +315,59 @@ func trimBST(root *TreeNode, low int, high int) *TreeNode { ``` +JavaScript版本: +迭代: +```js +var trimBST = function(root, low, high) { + if(root === null) { + return null; + } + while(root !==null &&(root.valhigh)) { + if(root.valhigh) { + cur.right = cur.right.left; + } + cur = cur.right; + } + return root; +}; +``` + +递归: +```js +var trimBST = function (root,low,high) { + if(root === null) { + return null; + } + if(root.valhigh) { + let left = trimBST(root.left,low,high); + return left; + } + root.left = trimBST(root.left,low,high); + root.right = trimBST(root.right,low,high); + return root; + } +``` + ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)