We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You can copy this wrapper and use typescript.
Type your solution inside the treeHeight function.
'usestrict';process.stdin.resume();process.stdin.setEncoding('utf-8');// process.stdin.setEncoding('ascii');letinputString:string='';letinputLines:string[]=[];letcurrentLine:number=0;process.stdin.on('data',function(inputStdin:string):void{inputString+=inputStdin;});process.stdin.on('end',function():void{inputLines=inputString.split(/\s/);inputString='';solution();});functionreadLine():string{returninputLines[currentLine++];}classTreeNode{data:number;left:null|TreeNode;right:null|TreeNode;constructor(data:number){this.data=data;this.left=null;this.right=null;}}classTree{root:TreeNode|null;constructor(){this.root=null;}insert(node:TreeNode,data:number){if(node==null){node=newTreeNode(data);}elseif(data<node.data){node.left=this.insert(node.left,data);}else{node.right=this.insert(node.right,data);}returnnode;}}// This is a "method-only" submission.// You only need to complete this method.functiontreeHeight(root:TreeNode):string{return"Your solution in here";}functionsolution(){vartree=newTree();varn=parseInt(readLine());for(vari=0;i<n;i++){varm=parseInt(readLine());tree.root=tree.insert(tree.root,m);}varheight=treeHeight(tree.root);process.stdout.write(height);}
Tree: Height of a Binary Tree
You are viewing a single comment's thread. Return to all comments →
The code provided for Javascript is broken.
You can copy this wrapper and use typescript. Type your solution inside the treeHeight function.