functionConvert(pRootOfTree) { if (!pRootOfTree) { returnnull } if (!pRootOfTree.left && !pRootOfTree.right) { return pRootOfTree } var left = Convert(pRootOfTree.left) var p = left while (p && p.right) { p = p.right } if (left) { p.right = pRootOfTree pRootOfTree.left = p } var right = Convert(pRootOfTree.right) if (right) { right.left = pRootOfTree pRootOfTree.right = right } return left||pRootOfTree }