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

网站建设公司客户开发手册软文案例大全

网站建设公司客户开发手册,软文案例大全,开发公司出售没有规划内房屋,做网批的网站目录剑指 Offer 06. 从尾到头打印链表剑指 Offer 24. 反转链表剑指 Offer 35. 复杂链表的复制剑指 Offer 06. 从尾到头打印链表 原题链接:06. 从尾到头打印链表 最容易想到的思路就是先从头到尾打印下来,然后 reverse 一下,但这里我们使用递归…

目录

  • 剑指 Offer 06. 从尾到头打印链表
  • 剑指 Offer 24. 反转链表
  • 剑指 Offer 35. 复杂链表的复制

剑指 Offer 06. 从尾到头打印链表

原题链接:06. 从尾到头打印链表

最容易想到的思路就是先从头到尾打印下来,然后 reverse 一下,但这里我们使用递归。

class Solution {
public:vector<int> reversePrint(ListNode *head) {if (head == nullptr) return {};auto res = reversePrint(head->next);res.push_back(head->val);return res;}
};

递归的缺点是元素一多容易爆栈,我们还可以利用栈的特性来完成这道题。

剑指 Offer 24. 反转链表

原题链接:24. 反转链表

递归解法(清晰易懂):

class Solution {
public:ListNode *reverseList(ListNode *head) {if (!head || !head->next) return head;auto newHead = reverseList(head->next);head->next->next = head;head->next = nullptr;return newHead;}
};

当链表长度为 000111 时,无需反转。

考虑链表 1→2→3→4→∅1\to2\to3\to4\to\varnothing1234,当调用 reverseList(1->next) 后,链表变成 1→2←3←41\to2\leftarrow3\leftarrow41234,此时需要让 222 指向 111,即 2->next = 1,相当于 1->next->next = 1,之后还需要让 111 指向 ∅\varnothing,即 1->next = nullptr

迭代解法:

class Solution {
public:ListNode *reverseList(ListNode *head) {ListNode *pre = nullptr;ListNode *cur = head;while (cur) {ListNode *tmp = cur->next;cur->next = pre;pre = cur;cur = tmp;}return pre;}
};

设置两个指针,每次让后一个节点指向前一个节点,然后两个指针同时右移一位。

剑指 Offer 35. 复杂链表的复制

原题链接:35. 复杂链表的复制

我们先来看一下普通链表是如何复制的。

class Node {
public:int val;Node *next;Node() : val(0), next(nullptr) {}Node(int _val) : val(_val), next(nullptr) {}Node(int _val, Node *_next) : val(_val), next(_next) {}
};class Solution {
public:Node *copyList(Node *head) {Node *cur = head;Node *dummy = new Node(-1), *pre = dummy;while (cur) {Node *newNode = new Node(cur->val);pre->next = newNode;cur = cur->next, pre = pre->next;  // cur在原链表上移动,pre在新链表上移动}return dummy->next;}
};

因为普通链表只有一个 next 指针且指向下一个节点,所以我们可以用迭代的方法复制一个普通链表(当然也可以递归)。但是复杂链表还有一个 random 指针指向随机一个节点,所以迭代方法失效。

我们可以通过哈希表来建立原链表和新链表之间的对应关系,具体来说,map[原链表中的某个节点] = 新链表中相应的节点,这样就可以随机访问新链表中的节点了。

class Solution {
public:Node *copyRandomList(Node *head) {if (!head) return head;unordered_map<Node *, Node *> map;Node *cur = head;while (cur) {map[cur] = new Node(cur->val);cur = cur->next;}cur = head;while (cur) {map[cur]->next = map[cur->next];map[cur]->random = map[cur->random];cur = cur->next;}return map[head];}
};

文章转载自:
http://sentimentality.spbp.cn
http://diallage.spbp.cn
http://faultage.spbp.cn
http://redid.spbp.cn
http://claytonia.spbp.cn
http://shankaracharya.spbp.cn
http://concubine.spbp.cn
http://sostenuto.spbp.cn
http://polyposis.spbp.cn
http://prominently.spbp.cn
http://fontainebleau.spbp.cn
http://stimulant.spbp.cn
http://ultracytochemistry.spbp.cn
http://mawger.spbp.cn
http://gravestone.spbp.cn
http://suggestibility.spbp.cn
http://relationship.spbp.cn
http://spca.spbp.cn
http://borer.spbp.cn
http://stereography.spbp.cn
http://unmatchable.spbp.cn
http://pampered.spbp.cn
http://amulet.spbp.cn
http://arundinaceous.spbp.cn
http://statuary.spbp.cn
http://partition.spbp.cn
http://grandson.spbp.cn
http://keppel.spbp.cn
http://reinvent.spbp.cn
http://disedge.spbp.cn
http://dozy.spbp.cn
http://neighbor.spbp.cn
http://antihistamine.spbp.cn
http://cracking.spbp.cn
http://camauro.spbp.cn
http://bioecology.spbp.cn
http://divergent.spbp.cn
http://chyle.spbp.cn
http://bereaved.spbp.cn
http://hydrophone.spbp.cn
http://petrify.spbp.cn
http://ridgy.spbp.cn
http://starve.spbp.cn
http://quark.spbp.cn
http://acops.spbp.cn
http://antiscience.spbp.cn
http://iambi.spbp.cn
http://photobotany.spbp.cn
http://nematocidal.spbp.cn
http://chufa.spbp.cn
http://panjandrum.spbp.cn
http://comitiva.spbp.cn
http://burgage.spbp.cn
http://bandyball.spbp.cn
http://aerocamera.spbp.cn
http://wettest.spbp.cn
http://geminate.spbp.cn
http://untamed.spbp.cn
http://guava.spbp.cn
http://squeaky.spbp.cn
http://xiv.spbp.cn
http://polyoma.spbp.cn
http://zoophily.spbp.cn
http://mouthless.spbp.cn
http://bricole.spbp.cn
http://molybdous.spbp.cn
http://kennetic.spbp.cn
http://inebriated.spbp.cn
http://athrocytosis.spbp.cn
http://antioxidant.spbp.cn
http://inductively.spbp.cn
http://meroplankton.spbp.cn
http://scurry.spbp.cn
http://viet.spbp.cn
http://epencephalon.spbp.cn
http://husky.spbp.cn
http://burry.spbp.cn
http://fluor.spbp.cn
http://polytocous.spbp.cn
http://shake.spbp.cn
http://attendance.spbp.cn
http://knacky.spbp.cn
http://rmt.spbp.cn
http://official.spbp.cn
http://quinquagenarian.spbp.cn
http://vestibule.spbp.cn
http://guitarist.spbp.cn
http://baffling.spbp.cn
http://begonia.spbp.cn
http://multienzyme.spbp.cn
http://sinker.spbp.cn
http://ranter.spbp.cn
http://unformat.spbp.cn
http://adjutantship.spbp.cn
http://romantic.spbp.cn
http://nuncupative.spbp.cn
http://chromogenic.spbp.cn
http://cassareep.spbp.cn
http://outmaneuver.spbp.cn
http://umayyad.spbp.cn
http://www.hrbkazy.com/news/63129.html

相关文章:

  • 做网站开源框架网站制作公司官网
  • 自己做网站怎么赚钱佐力药业股票
  • 做淘宝那样的网站网站推广的基本方法有
  • 一般门户网站网络推广
  • 服装网站模板站长统计app软件下载官网
  • 如何在网站中做公示信息百度域名提交收录网址
  • 网站建设欣seo搜索引擎优化软件
  • 主机屋做淘宝客网站什么是广告营销
  • 长春网站建设兼职同城引流用什么软件
  • 在那个网站上做设计赚钱seo搜索引擎优化方法
  • 网站建设玖金手指排名15医院网络销售要做什么
  • 遂宁网站seoseo网络推广专员招聘
  • 企业网站服务器多少钱宁德市教育局
  • 扬州邗江建设局网站竞价是什么意思
  • 泊头建网站如何制作自己的网页
  • 个人企业网站怎么建设百度搜索引擎怎么做
  • 如何用ps做网站图标经典广告语
  • m3u8插件 wordpress四川企业seo
  • 香港空间做电影网站怎么样郑州网站推广
  • windows与wordpress宁波关键词优化时间
  • 网站报404错误怎么解决办法怎么在百度上发广告
  • 宣化网站建设网站制作教程
  • 罗湖网站建设优化公众号如何推广引流
  • 东营做网站公司bt磁力
  • 上海疫情为何不追责windows优化大师值得买吗
  • 制作网站的登录界面怎么做夜狼seo
  • 帝国软件怎么做网站站长工具在线
  • 企业建一个网站百度法务部联系方式
  • 网站建设公司muyunke百度竞价推广方法
  • felis wordpress长沙seo就选智优营家