Javascript的结构体应用,如下:
    function station(name, latitude, longitude){
        this.name = name;
        this.latitude = latitude;
        this.longitude = longitude;
    }
    var s1 = new station('station1', 100, 200);
    console.log(s1.name+" 's latitude :" + s1.latitude );

/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} l1
* @param {ListNode} l2
* @return {ListNode}
*/ var addTwoNumbers = function(l1, l2) {
var head = new ListNode(0);
var temp1 = 0;
var temp2 = 0;
var val1;
var val2;
while(l1 || l2 || temp1) {
if (l1)val1 = l1.val;
else val1 = 0;
if (l2) val2 = l2.val;
else val2 = 0;
temp2 = Math.floor((val1 + val2 + temp1) % 10);
temp1 = Math.floor((val1 + val2 + temp1) / 10);
head.val += 1;
var newNode = new ListNode(temp2);
if(head.next == null){
head.next = newNode;
}
else {
var tempNode = head.next;
while(tempNode.next != null)
tempNode = tempNode.next;
tempNode.next = newNode;
}
if (l1)l1 = l1.next;
if (l2)l2 = l2.next;
}
return head.next;
};

[leetcode]Add Two Numbers——JS实现的更多相关文章

  1. [LeetCode] Add Two Numbers II 两个数字相加之二

    You are given two linked lists representing two non-negative numbers. The most significant digit com ...

  2. [LeetCode] Add Two Numbers 两个数字相加

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  3. LeetCode Add Two Numbers II

    原题链接在这里:https://leetcode.com/problems/add-two-numbers-ii/ 题目: You are given two linked lists represe ...

  4. LeetCode: Add Two Numbers 解题报告

    Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are ...

  5. Leetcode:Add Two Numbers分析和实现

    Add Two Numbers这个问题的意思是,提供两条链表,每条链表表示一个十进制整数,其每一位对应链表的一个结点.比如345表示为链表5->4->3.而我们需要做的就是将两条链表代表的 ...

  6. [LeetCode] Add Two Numbers题解

    Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. Th ...

  7. [Leetcode] Add two numbers 两数之和

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  8. [LeetCode] Add Two Numbers

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...

  9. LeetCode——Add Two Numbers

    Question:You are given two linked lists representing two non-negative numbers. The digits are stored ...

随机推荐

  1. 百度知道的代码复制粘贴到VB没有换行怎么办

    在如下所示的网页中,复制 粘贴到word文档,换行还是有的   再复制到VB6.0中还是可用的

  2. bzoj 1266 [AHOI2006] 上学路线 route 题解

    转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23989499 [原题] 1266: [AHOI2006]上学路线route Time ...

  3. rsh 无秘钥登陆配置

    /etc/hosts.equiv里的主机不须要提供password就能够訪问本机./etc/host.equiv 要和~/.rhosts文件连用. [root@web-htl2-01 ~]# cat ...

  4. 对“使用MyEclipse,写的jsp代码因有汉字而无法保存”问题的解决

    使用MyEclipse编辑jsp时.有时会出现"使用MyEclipse,写的jsp代码因有汉字而无法保存"的现象,怎样解决呢? Window-->Preferences--& ...

  5. java多线程之 ---- 线程死锁

    java多线程之线程死锁 产生死锁的主要原因: 由于系统资源不足. 进程执行推进的顺序不合适. 资源分配不当等. 假设系统资源充足.进程的资源请求都可以得到满足,死锁出现的可能性就非常低.否则就会因争 ...

  6. HTTPie: a CLI, cURL-like tool for humans

    HTTPie github HTTPie 是用 Python 编写,用到了 Requests 和 Pygments 这些出色的库. 主要特性: 直观的语法 格式化和色彩化的终端输出 内置 JSON 支 ...

  7. Use of implicitly declared global variable

    https://stackoverflow.com/questions/7604419/resharper-javascript-use-of-implicitly-declared-global-v ...

  8. [翻译]NUnit--Getting Started(二)

    Getting Started with NUnit 如果你打算开始学习,到下载页面选择一个NUnit版本.安装页面包含了安装说明. 开始NUnit阅读Quick Start页面.验证了一个C#银行应 ...

  9. android 添加手机短信,获取手机短信,删除手机短信和修改手机短信

    注意添加权限: <uses-permission android:name="android.permission.READ_SMS"></uses-permis ...

  10. MySql 5.7 Archive 版本安装失败 解决过程

    下载地址 https://dev.mysql.com/downloads/mysql/5.7.html#downloads 按照网络教程: 创建my.ini 文件,并填写配置内容: [mysql] # ...