zoukankan      html  css  js  c++  java
  • 1

    /**
     * @param {string} s
     * @return {number}
     */
    var lengthOfLongestSubstring = function(s) {

    };
     
     
     
    var addTwoNumbers = function(l1, l2) {
    let a = l1;
    let b = l2;
    let he = 0;
    let item = 1;
    let jinOne = 0;
    let newC = null;
    let head = null;
    let i =0;
    while(a!=null||b!=null){
    let tHe = 0;
    if(a!=null)
    tHe = a.val;
    else
    tHe = 0;
    if(b!=null)
    tHe = tHe+b.val;
    else
    tHe =tHe;

    he =tHe;
    if(he > 10) {
    he = he % 10+jinOne;
    jinOne = 1;
    }else{
    he = he+jinOne
    jinOne = 0;
    }
     
    let newHe = new ListNode(he);
    newHe.next=null;
    if(i==0){
    newC = newHe;
    head = newC;
    }else{
    newC.next = newHe;
    newC = newHe;
    }
    i++;
    //console.log(he)
    if(a!=null) a=a.next;
    if(b!=null) b=b.next;
    }

    return head
    };
     
    //-------------
     
    function ListNode(val) {
        this.val = val;
        this.next = null;
    }
    /*
    let a1 = new ListNode(0);
        a2 = new ListNode(1);
    //a3 = new ListNode(3);
    let b1 = new ListNode(0);
       // b2 = new ListNode(6),
       // b3 = new ListNode(4);
    a1.next=a2;a2.next=null;//a3;a3.next=null;
    b1.next=null;//b2.next=b3;b3.next=null;    
    */
    let  arr = '1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1'.split(',')
    let brr = '5,6,4'.split(',')
    let aHead =null;

    function getList(str){
        let  myarr = '1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1'.split(',')
        let a =new ListNode(parseInt(arr[0]))
        for(let i=1;i<arr.length;i++){
            let newC = new ListNode(parseInt(arr[i]))
            newC.next = null;
            a.next = newC;
            a=newC;
        }
        a.next = null;
        return a;
    }

    function printL(a){
     while(a!=null){
        console.log(a.val)
        a=a.next
     }
    }

    let a1 = getList('1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1')
    let b1 = getList('5,6,4')

    printL(a1)



    var addTwoNumbers = function(l1, l2) {
       let a = l1;
       let b = l2;
       let he = 0;
       let item = 1;
       while(a!=null||b!=null){
           let tHe = 0;
           if(a!=null) 
             tHe = a.val;
           else
              tHe = 0;
           if(b!=null)  
              tHe = tHe+b.val;
            else
              tHe =tHe;

           he = he+tHe*item;
           item = item *10;
           if(a!=null) a=a.next;
           if(b!=null) b=b.next;

       }
       console.log(he)
       let cItem = he%10
       let c = new ListNode(cItem)
       let head = c;
       while(he>=10){
            he =parseInt (he/10)
            cItem = he %10
            let newC = new ListNode(cItem)
            newC.next = null;
            c.next = newC;
            c = newC;
       }
       return head
     };

     let h = addTwoNumbers(a1,b1)

    let a = h

     while(a!=null){
        console.log(a.val)
        a=a.next
     }
  • 相关阅读:
    3个检测浏览器UserAgent信息的网站
    linux系统下配置网桥(CentOS 5.5)
    squid封禁不带UserAgent的请求
    iptables透明网桥无法使用透明代理错误
    Squid修改用户浏览器的Useragent信息
    MySQL主从复制(MasterSlave)与读写分离(MySQLProxy)实践
    js中格式化时间
    js获取当前月的第一天和最后一天
    JS String.toDate
    Js获取当前日期时间及其它操作
  • 原文地址:https://www.cnblogs.com/cnchengv/p/13296466.html
Copyright © 2011-2022 走看看