当前位置: 首页 > news >正文

福建网站建设网seo是什么意思的缩写

福建网站建设网,seo是什么意思的缩写,做幼儿园网站,手机微网站建设文章目录 链表题的一些总结两种链表定义set存储链表节点,存的是整个空间同时处理长短不一的两个链表处理方法 while(l1 || l2)处理方法 while(l1 & l2) dummyhead的使用 链表题的一些总结 两种链表定义 class class ListNode {val;next null;constructor(va…

文章目录

  • 链表题的一些总结
    • 两种链表定义
    • set存储链表节点,存的是整个空间
    • 同时处理长短不一的两个链表
      • 处理方法 while(l1 || l2)
      • 处理方法 while(l1 & l2)
    • dummyhead的使用

链表题的一些总结

两种链表定义

  • class
class ListNode {val;next = null;constructor(value) {this.val = value;this.next = null;}
}
  • function
function ListNode(val, next) {this.val = val === undefined ? 0 : val;this.next = next === undefined ? null : next;
}

set存储链表节点,存的是整个空间

  • 相交链表
/*** Definition for singly-linked list.* function ListNode(val) {*     this.val = val;*     this.next = null;* }*//*** @param {ListNode} headA* @param {ListNode} headB* @return {ListNode}*/
var getIntersectionNode = function(headA, headB) {const set = new Set();let tmp = headA;while(tmp) {if(!set.has(tmp)) {set.add(tmp);}tmp = tmp.next;}tmp = headB;while(tmp) {if(set.has(tmp)) {return tmp;}tmp = tmp.next;  }return null;
};

同时处理长短不一的两个链表

处理方法 while(l1 || l2)

  • 两数相加
/*** Definition for singly-linked list.* function ListNode(val, next) {*     this.val = (val===undefined ? 0 : val)*     this.next = (next===undefined ? null : next)* }*/
/*** @param {ListNode} l1* @param {ListNode} l2* @return {ListNode}*/
var addTwoNumbers = function(l1, l2) {let head = new ListNode(0);let cur = head;let carry = 0;while(l1 != null || l2 != null) {const n1 = l1 != null ? l1.val : 0;const n2 = l2 != null ? l2.val : 0;let sum = n1 + n2 + carry;carry = Math.floor(sum / 10);sum = sum % 10;let tmp = new ListNode(sum, null);cur.next = tmp;cur = tmp;if(l1 != null) {l1 = l1.next;}if(l2 != null) {l2 = l2.next;}}if(carry === 1) {let tmp = new ListNode(1, null);cur.next = tmp;cur = tmp;}return head.next;
};

处理方法 while(l1 & l2)

不能用或,如果一个链表之后为空了,就没有比较的必要

  • 合并有序链表
  • 超出时间限制
var mergeTwoLists = function(list1, list2) {let dummyhead = new ListNode(-1);let h = dummyhead;while(list1 || list2) {if(list1 === null) {h.next = list2;} else if(list2 === null) {h.next = list1;} else {if(list1.val < list2.val) {h.next = list1;h = list1;list1 = list1.next;} else {h.next = list2;h = list2;list2 = list2.next;}}}return h.next;
};
  • 不超出时间限制
/*** Definition for singly-linked list.* function ListNode(val, next) {*     this.val = (val===undefined ? 0 : val)*     this.next = (next===undefined ? null : next)* }*/
/*** @param {ListNode} list1* @param {ListNode} list2* @return {ListNode}*/
var mergeTwoLists = function(list1, list2) {let dummyhead = new ListNode(-1);let h = dummyhead;while(list1 && list2) {if(list1.val < list2.val) {h.next = list1;h = list1;list1 = list1.next;} else {h.next = list2;h = list2;list2 = list2.next;}}if(list1 === null) {h.next = list2;} else if(list2 === null) {h.next = list1;}return dummyhead.next;
};

dummyhead的使用

返回时 dummyhead.next

http://www.hkea.cn/news/198573/

相关文章:

  • 广药网站建设试卷株洲最新今日头条
  • 网站建设管理考核办法微信推广平台怎么做
  • 网站新闻模块代码网络推广有哪些常见的推广方法
  • 合肥大型网站如何推广普通话
  • 高端网站制作软件怎么样推广自己的店铺和产品
  • 无障碍浏览网站怎么做关键词seo排名优化推荐
  • wordpress 247seo推广系统
  • 做深圳门户网站起什么名字好泰州seo外包公司
  • 网站视频上传怎么做百度站长平台论坛
  • wordpress农业模板下载小时seo
  • 做网站语言排名2018发帖推广哪个平台好
  • 销氪crmseo入门讲解
  • 蒙阴哪有做淘宝网站的钓鱼网站制作教程
  • 网站如何做导航条下拉菜单怎么做百度网页
  • 网站开发都做什么平台推广精准客源
  • 网站建设共享ip宁波seo搜索引擎优化
  • 学校网站建设必要性搜索引擎排名
  • 哪里有做区块链网站的百度网址大全在哪里找
  • 加盟平台网站怎么做竞价托管多少钱一个月
  • wordpress 微信 代码网站关键词怎么优化排名
  • 网站推广维护考研培训班哪个机构比较好
  • 网站后台生成器人工智能培训班收费标准
  • 在线做app的网站武汉网络营销公司排名
  • 了解深圳网站页面设计潍坊百度关键词优化
  • 制作网站怎样找公司来帮做seo词条
  • 网络销售有哪些站长工具seo排名
  • 做房产中介网站怎么注册一个自己的网站
  • 天津网站设计成功柚米全网推广成功再收费
  • 建设公司网站靠谱吗企业网站设计制作
  • 电子商务学什么课程内容兰州搜索引擎优化