function flattenTree( root ) { // write code here if(root == null) return null flattenTree(root.left) flattenTree(root.right) let left = root.left let right = root.right root.left = null root.right = left let cur = root while(cur.right != null) { cur = cur.right } cur.right = right return root }