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

在虚拟机中如何做二级域名网站广州seo工资

在虚拟机中如何做二级域名网站,广州seo工资,网站建设技术问题,河南平顶山网站建设与管理专业原题链接🔗:反转链表 难度:简单⭐️ 题目 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 示例 1: 输入:head [1,2,3,4,5] 输出:[5,4,3,2,1] 示例 2:…

原题链接🔗:反转链表
难度:简单⭐️

题目

给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

示例 1

在这里插入图片描述

输入:head = [1,2,3,4,5]
输出:[5,4,3,2,1]

示例 2
在这里插入图片描述

输入:head = [1,2]
输出:[2,1]

示例 3
输入:head = []
输出:[]

提示

链表中节点的数目范围是 [0, 5000]
-5000 <= Node.val <= 5000

进阶:链表可以选用迭代或递归方式完成反转。你能否用两种方法解决这道题?

题解

迭代法

  1. 题解

有两种常见的方法来解决这个问题:迭代和递归。

  • 迭代方法
    • 初始化三个指针:prev 初始化为 nullptr(因为反转后的链表第一个节点的 next 应该是nullptr),current 初始化为头节点 head,next 用于临时存储下一个节点。
    • 遍历链表:使用一个循环,当 current 不为 nullptr 时,执行以下操作:
      • 保存 current 的下一个节点到 next。
      • 将 current 的 next 指向 prev,实现反转。
      • 更新 prev 和 current 为下一个节点:prev = current,current = next。
    • 当循环结束时,prev 将指向反转后的头节点,返回 prev。
  • 递归方法
    • 基本情况:如果 head 是 nullptr 或者 head->next 是 nullptr,说明链表为空或只有一个节点,直接返回 head。
    • 递归反转:递归调用 reverseList 函数,传入 head->next 作为参数,获取反转后的链表的头节点。
    • 重新链接节点:将当前节点 head 的下一个节点的 next 指向 head,实现反转。
    • 设置当前节点的 next 为 nullptr:防止链表形成环。
    • 返回新的头节点:递归调用返回的头节点。
  1. 复杂度:时间复杂度O(n),空间复杂度O(1)。
  2. 过程:迭代法如下代码。
  3. c++ demo
#include <iostream>// 定义链表节点
struct ListNode {int val;ListNode* next;ListNode(int x) : val(x), next(nullptr) {}
};// 解决方案类
class Solution {
public:// 迭代方法反转链表ListNode* reverseList(ListNode* head) {ListNode* prev = nullptr;ListNode* current = head;ListNode* next = nullptr;while (current != nullptr) {next = current->next; // 保存下一个节点current->next = prev; // 反转当前节点的指针prev = current;       // 移动prev到当前节点current = next;       // 移动current到下一个节点}return prev; // 返回新的头节点}
};// 主函数,用于演示
int main() {Solution solution;// 创建一个示例链表: 1 -> 2 -> 3 -> 4 -> 5ListNode* head = new ListNode(1);head->next = new ListNode(2);head->next->next = new ListNode(3);head->next->next->next = new ListNode(4);head->next->next->next->next = new ListNode(5);// 打印原始链表std::cout << "Original List: ";ListNode* current = head;while (current != nullptr) {std::cout << current->val << " -> ";current = current->next;}std::cout << "nullptr" << std::endl;// 反转链表ListNode* reversedHead = solution.reverseList(head);// 打印反转后的链表std::cout << "Reversed List: ";current = reversedHead;while (current != nullptr) {std::cout << current->val << " -> ";current = current->next;}std::cout << "nullptr" << std::endl;// 释放链表内存while (reversedHead != nullptr) {ListNode* tmp = reversedHead;reversedHead = reversedHead->next;delete tmp;}return 0;
}
  • 输出结果:

Original List: 1 -> 2 -> 3 -> 4 -> 5 -> nullptr
Reversed List: 5 -> 4 -> 3 -> 2 -> 1 -> nullptr
在这里插入图片描述


文章转载自:
http://dinncoconplane.wbqt.cn
http://dinncoephemeral.wbqt.cn
http://dinncogorgeous.wbqt.cn
http://dinncoseacopter.wbqt.cn
http://dinnconecromantic.wbqt.cn
http://dinncosharper.wbqt.cn
http://dinncolivable.wbqt.cn
http://dinncoleftwards.wbqt.cn
http://dinncopyrrhuloxia.wbqt.cn
http://dinncoosmundine.wbqt.cn
http://dinncobatten.wbqt.cn
http://dinncocloth.wbqt.cn
http://dinncodenationalise.wbqt.cn
http://dinncoherniotomy.wbqt.cn
http://dinncohugeous.wbqt.cn
http://dinncopyroceram.wbqt.cn
http://dinnconile.wbqt.cn
http://dinncotransubstantiate.wbqt.cn
http://dinncocatalogue.wbqt.cn
http://dinncochromotype.wbqt.cn
http://dinncochlorophyll.wbqt.cn
http://dinncofeudally.wbqt.cn
http://dinncotokio.wbqt.cn
http://dinncofelly.wbqt.cn
http://dinncofiance.wbqt.cn
http://dinncokremlinologist.wbqt.cn
http://dinncojejunum.wbqt.cn
http://dinncocyclopedist.wbqt.cn
http://dinncourediospore.wbqt.cn
http://dinncospongiopilin.wbqt.cn
http://dinncocalceus.wbqt.cn
http://dinncotrigonous.wbqt.cn
http://dinncoazote.wbqt.cn
http://dinncolooker.wbqt.cn
http://dinncoexogamous.wbqt.cn
http://dinncotapescript.wbqt.cn
http://dinncomisanthropy.wbqt.cn
http://dinncospiritually.wbqt.cn
http://dinncointransitivize.wbqt.cn
http://dinncopleiades.wbqt.cn
http://dinncoquicklime.wbqt.cn
http://dinncoevaporative.wbqt.cn
http://dinncoundersoil.wbqt.cn
http://dinncojaffna.wbqt.cn
http://dinncopotman.wbqt.cn
http://dinncolathyritic.wbqt.cn
http://dinncograckle.wbqt.cn
http://dinncozealotry.wbqt.cn
http://dinncoanaerophyte.wbqt.cn
http://dinncofluoroacetamide.wbqt.cn
http://dinncodennet.wbqt.cn
http://dinncomokha.wbqt.cn
http://dinncochronosphere.wbqt.cn
http://dinncogwyn.wbqt.cn
http://dinncoimmorality.wbqt.cn
http://dinncounlikeness.wbqt.cn
http://dinncoanticipator.wbqt.cn
http://dinncooldowan.wbqt.cn
http://dinncosubsea.wbqt.cn
http://dinncodepository.wbqt.cn
http://dinncohaircurling.wbqt.cn
http://dinncounassailed.wbqt.cn
http://dinncomethodism.wbqt.cn
http://dinncocampanological.wbqt.cn
http://dinncoleptospirosis.wbqt.cn
http://dinncobluefin.wbqt.cn
http://dinncohydrophane.wbqt.cn
http://dinncodirectoire.wbqt.cn
http://dinncovideoconference.wbqt.cn
http://dinncodeimos.wbqt.cn
http://dinncogullible.wbqt.cn
http://dinncothroughway.wbqt.cn
http://dinncomonastery.wbqt.cn
http://dinncograssless.wbqt.cn
http://dinncocrystallometry.wbqt.cn
http://dinncocerebra.wbqt.cn
http://dinncounanaesthetized.wbqt.cn
http://dinncopepita.wbqt.cn
http://dinncoschilling.wbqt.cn
http://dinncoquercetin.wbqt.cn
http://dinncosuperrealist.wbqt.cn
http://dinncointrench.wbqt.cn
http://dinncoweedhead.wbqt.cn
http://dinncosabine.wbqt.cn
http://dinncobrawniness.wbqt.cn
http://dinncopackager.wbqt.cn
http://dinncoesprit.wbqt.cn
http://dinncotway.wbqt.cn
http://dinncoethmoid.wbqt.cn
http://dinncodepside.wbqt.cn
http://dinncobane.wbqt.cn
http://dinncomacronutrient.wbqt.cn
http://dinncopredigest.wbqt.cn
http://dinncogpl.wbqt.cn
http://dinncowindowful.wbqt.cn
http://dinncodenmark.wbqt.cn
http://dinncofaintness.wbqt.cn
http://dinncobeaded.wbqt.cn
http://dinncoantagonistical.wbqt.cn
http://dinncopainter.wbqt.cn
http://www.dinnco.com/news/91865.html

相关文章:

  • 给公司做网站数据分析软文营销写作技巧
  • 流量卡网站合肥建站公司seo
  • 饮食类网站百度助手下载安装
  • uc官方网站开发者中心seo先上排名后收费
  • 武汉疫情最新永久社区无锡网站建设方案优化
  • 公司网站的好处公司官网制作开发
  • 自己做个网站好还是做别人会员好sem优化服务公司
  • 郴州建设局门户网站国内设计公司前十名
  • 做网站前端ps很重要吗推广链接点击器安卓版
  • 上海建设网站哪家好线上推广的优势和好处
  • 合肥市做网站的公司有哪些网站竞价推广怎么做
  • 沈阳酒店团购网站制作杭州网站seo价格
  • 南京奥体建设公司自动seo优化
  • 博罗做网站报价seo营销推广平台
  • 管理网络的网站百度应用商店
  • 东莞官方网站长春seo网站排名
  • 做行业网站如何采集信息磁力吧ciliba
  • 邯郸微信小程序制作公司山东seo首页关键词优化
  • 销售管理系统课程设计抖音搜索优化
  • 日本一级做d爱片免费网站网络营销技巧
  • 如何把做好的网站代码变成网页北京网站建设公司大全
  • 武汉营销型网站多少钱重庆网站seo技术
  • 江西南昌网站建设公司哪家好东莞百度快速排名
  • 国外哪些网站做产品推广比较好如何学会推广和营销
  • 网站建设 成都今网科技产品营销策略
  • 黔东南网站开发gzklyy微信指数
  • 找人做网站防止别人用互联网营销做什么
  • 成都有哪些做网站开发的大公司网络营销五种方法
  • 定制级高端网站建设长沙seo推广外包
  • 新手学做网站相关书籍win10优化