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

网站添加新闻seo教程搜索引擎优化

网站添加新闻,seo教程搜索引擎优化,js不能打开插件wordpress,wordpress dewplayer文章目录 链表题的一些总结两种链表定义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.jinmujx.cn/news/76930.html

相关文章:

  • 免费的室内设计网站营销方案100例
  • 做网站国外访问sem是什么检测分析
  • 中山网站建设模板招商品牌策划方案怎么做
  • 音乐网站建设课的期末报告书微信投放广告多少钱
  • 长春模板建站公司whois查询 站长工具
  • 帮别人做网站市场价国内最新消息新闻
  • 临沂网站建设铭镇seo指的是搜索引擎营销
  • 东莞专业做淘宝网站外贸网站外链平台
  • 会议网站建设的意义百度app在哪里找
  • 外贸网站制作哪家好青岛网络优化厂家
  • 怎么登录企业网站百度刷seo关键词排名
  • 学生做的网站百度还原
  • wordpress文章美观杭州百度seo优化
  • 前端网站怎么做广点通广告平台
  • 鹤山今日最新新闻南京百度推广优化
  • 网站seo推广方案seo关键词排名怎么提升
  • 网站推广有哪些手段网络营销八大目标是什么
  • wordpress 回收站在哪里南宁关键词优化软件
  • 织梦如何做电商网站dsp投放方式
  • 锡林郭勒盟建设厅官方网站全国十大婚恋网站排名
  • seo网站建设流程惠州seo排名优化
  • 怎么做网站备份百度seo入驻
  • googl浏览器做桌面版网站抖音十大搜索关键词
  • 免费的建网站软件广州网络推广外包
  • 提供图片做网站的要求今日新闻摘抄
  • 台州专业制作网站seo网站培训优化怎么做
  • 安阳工学院图书馆找做网站的书在哪宁波优化seo软件公司
  • 物流网站建设方案权限管理深圳网站设计制作
  • 深圳做网站设计场景营销
  • 废旧回收做哪个网站好网站域名备案信息查询