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. dorker 安装

    http://www.docker.org.cn/book/install/install-docker-win7-win8-requirements-38.html1. 你先去下载Docker To ...

  2. Wget下载多个链接

    需要wget下载多个文件链接时,可以采用如下方法: 1. 将链接存入文件url.list中: 2. wget -bc -i url.list -o [log_file] -P [target_dir] ...

  3. 三星手机root后开启调试模式

    背景说明:三星手机高版本的手机进行root后也无法安装xposed,无法开启debuggable,使用androistdio无法进行调试. 1 .连接ddms无法显示正在运行的进程. 2.安装mpro ...

  4. nRF52832之硬件I2C

    这几天一直在折腾nRF52832的硬件I2C,到了今天最终出现了成果,在此也印证了那句话:"耕耘就有收获" 52832的硬件I2C尽管官方提供了demo,可是自己对I2C通信理解的 ...

  5. 使用 dva + antd 快速开发react应用

    使用 dva + antd 快速开发react应用 版本说明: 注意:dva的版本是0.9.2 $ node -v v10.2.1 $ npm -v $ dva -v dva-cli version ...

  6. python3 使用http.server模块 搭建一个简易的http服务器

    from http.server import HTTPServer, BaseHTTPRequestHandler import json data = {'result': 'this is a ...

  7. 第二次PHP面试题

    昨天下午翘班去参加了人生中第二次PHP面试.是一家相对第一家更加专业的互联网公司.效果不如第一家理想,笔试题有点难,而且偏高理论,面试时面试官也还不错,一起探讨,可是他的问题我还是很多都不知道,果然是 ...

  8. Robot Framework 初学者上手资料

    首先要声明一下这是从http://www.cnblogs.com/yufeihlf/p/5949984.html拷贝的. 在这里只是自己的一个笔记,方便日后添加.修改内容. 总结下Robot Fram ...

  9. 玲珑学院OJ 1028 - Bob and Alice are playing numbers 字典树,dp

    http://www.ifrog.cc/acm/problem/1028 题解处:http://www.ifrog.cc/acm/solution/4 #include <cstdio> ...

  10. A bad vacation

    My story happened in the winter of 2012, the first year I began to work in Beijing. It was a cold we ...