Same Tree
/** Definition for a binary tree node. * Function TreeNode (val) {* This.val = val; * This.left = This.right = Null * } *//** * @param {TreeNode} p * @param {TreeNode} Q * @return {Boolean}*/varIssametree =function(p, q) {if(p===NULL&&q===NULL){ return true; } if(p===NULL&&q!==NULL){ return false; } if(q===NULL&&p!==NULL){ return false; } if(p.val!==q.val) { return false; } if(Issametree (P.left,q.left) &&Issametree (p.right,q.right)) { return true; } Else{ return false; } };
Judging two binary trees is not the same, my idea is that all kinds of situations listed, error is false, and then false will always float to the top, and finally return the correct boolean value.
Your runtime beats 74.85% of Javascriptsubmissions
171. Excel Sheet Column Number
/* * * @param {string} s * @return {number}
*/ var titletonumber = function (s) { var SL = s.length; var sc,result=0,i=0; while (Sl!==0 = S.charat ( Sl-1); Result = (sc.charcodeat () -64) *math.pow (26,i) +result; SL --; I ++; return result;};
This problem is mainly used in function charat (); charCodeAt (); Math.pow (x, y) is equivalent to converting to 26 binary operations, and the conversion between letters and numbers is done with ASCII code.
Your runtime beats 22.00% of javascriptsubmissions. I don't know why my method is always so spicy chicken--. When you have the chance to do it for the second time.
Leetcode JavaScript implementation 100. Same Tree 171. Excel Sheet Column Number