Leetcode JavaScript implementation 100. Same Tree 171. Excel Sheet Column Number

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.