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

镇江做网站多少钱百度官方版

镇江做网站多少钱,百度官方版,建设部网站材料价格上涨规定,2019做网站需要营业执照吗文章目录 [toc]问题描述数据范围示例 C代码实现使用栈实现(不符合要求,仅作为思路) 解题思路 - 原地反转链表步骤 C语言代码实现 以前只用过C刷过代码题目,现在试着用C语言刷下 问题描述 给定一个单链表的头结点 pHead&#xff…

文章目录

      • @[toc]
      • 问题描述
        • 数据范围
        • 示例
      • C++代码实现
        • 使用栈实现(不符合要求,仅作为思路)
      • 解题思路 - 原地反转链表
        • 步骤
      • C语言代码实现

以前只用过C++刷过代码题目,现在试着用C语言刷下

问题描述

给定一个单链表的头结点 pHead,反转该链表后返回新链表的表头。
在这里插入图片描述

数据范围
  • 链表长度 0 ≤ n ≤ 1000 0 \leq n \leq 1000 0n1000
  • 要求:空间复杂度 O ( 1 ) O(1) O(1),时间复杂度 O ( n ) O(n) O(n)
示例
  1. 输入:{1,2,3}
    输出:{3,2,1}

  2. 输入:{}
    输出:{}

如果链表为空,则直接返回空。


C++代码实现

最开始尝试用 C++ 的 实现,结果想到C语言不能直接调用栈,玛德。但考虑到题目要求空间复杂度为 O ( 1 ) O(1) O(1),栈的实现并不符合要求。

使用栈实现(不符合要求,仅作为思路)
#include <stack>
#include <iostream>
using namespace std;// 定义链表节点
struct ListNode {int val;struct ListNode* next;ListNode(int x) : val(x), next(nullptr) {}
};// 使用栈实现链表反转
struct ListNode* ReverseList(struct ListNode* head) {if (head == nullptr)  // 空链表直接返回return head;stack<ListNode*> st;  // 定义一个栈ListNode* cur = head;// 将所有节点压入栈while (cur != nullptr) {st.push(cur);cur = cur->next;}// 弹出栈顶元素作为新链表头ListNode* newHead = st.top();st.pop();cur = newHead;// 重新连接链表while (!st.empty()) {cur->next = st.top();st.pop();cur = cur->next;}cur->next = nullptr;  // 终止链表return newHead;
}

此代码能实现反转,但使用了辅助栈,空间复杂度为 O ( n ) O(n) O(n),不符合题目要求。


解题思路 - 原地反转链表

为了满足空间复杂度 O ( 1 ) O(1) O(1) 的要求,我们使用三个指针实现链表的 原地反转

步骤
  1. 初始化

    • prev:指向当前节点的前驱节点(初始为 NULL)。
    • cur:指向当前节点。
    • next:临时保存当前节点的后继节点。
  2. 反转过程

    • 逐一将当前节点的 next 指针指向 prev
    • prevcur 向后移动。
  3. 结束条件

    • cur 遍历到链表尾部(即 cur ->next== NULL),同时别忘了,把最后一个结点也给处理了,cur->next=pre。链表反转完成,此时 cur 即为新链表头。

C语言代码实现

/*** struct ListNode {*	int val;*	struct ListNode *next;* };*/
/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** * @param head ListNode类 * @return ListNode类*/
struct ListNode* ReverseList(struct ListNode* head ) {if(head==NULL)return head;struct ListNode* cur=head;struct ListNode* pre=NULL;struct ListNode* next=cur->next;while(cur->next!=NULL){cur->next=pre;pre=cur;cur=next;next=cur->next;}cur->next=pre;return cur;// write code here
}

轻松拿捏。


文章转载自:
http://illuminative.c7500.cn
http://rise.c7500.cn
http://washwoman.c7500.cn
http://fabricius.c7500.cn
http://airspeed.c7500.cn
http://aroma.c7500.cn
http://encomiast.c7500.cn
http://buttermilk.c7500.cn
http://confabulation.c7500.cn
http://honoria.c7500.cn
http://preoviposition.c7500.cn
http://hypercythemia.c7500.cn
http://aperture.c7500.cn
http://esurient.c7500.cn
http://pitiable.c7500.cn
http://apolune.c7500.cn
http://nonsignificant.c7500.cn
http://siwan.c7500.cn
http://taradiddle.c7500.cn
http://chasmic.c7500.cn
http://workboat.c7500.cn
http://tealess.c7500.cn
http://isodose.c7500.cn
http://bouzoukia.c7500.cn
http://dehortative.c7500.cn
http://controllable.c7500.cn
http://killfile.c7500.cn
http://dimm.c7500.cn
http://conservative.c7500.cn
http://sozin.c7500.cn
http://dealate.c7500.cn
http://gyp.c7500.cn
http://frolicly.c7500.cn
http://vomitory.c7500.cn
http://filiety.c7500.cn
http://autotrophic.c7500.cn
http://lithemia.c7500.cn
http://semitruck.c7500.cn
http://sulfite.c7500.cn
http://voroshilovgrad.c7500.cn
http://shredder.c7500.cn
http://smelter.c7500.cn
http://adorably.c7500.cn
http://doublethink.c7500.cn
http://zonal.c7500.cn
http://imco.c7500.cn
http://conduit.c7500.cn
http://phantasmagoric.c7500.cn
http://kaoline.c7500.cn
http://autosuggestion.c7500.cn
http://ducktail.c7500.cn
http://quite.c7500.cn
http://mulatta.c7500.cn
http://lebensraum.c7500.cn
http://johnston.c7500.cn
http://stearic.c7500.cn
http://gag.c7500.cn
http://dissuade.c7500.cn
http://injuriously.c7500.cn
http://sigh.c7500.cn
http://apiarist.c7500.cn
http://antiremonstrant.c7500.cn
http://autocorrelation.c7500.cn
http://xat.c7500.cn
http://taproot.c7500.cn
http://frontlet.c7500.cn
http://unlessoned.c7500.cn
http://mechanochemical.c7500.cn
http://maluation.c7500.cn
http://inferno.c7500.cn
http://lorrie.c7500.cn
http://supernutrition.c7500.cn
http://earthling.c7500.cn
http://coxcombry.c7500.cn
http://spoffish.c7500.cn
http://dualism.c7500.cn
http://disentangle.c7500.cn
http://breton.c7500.cn
http://ailing.c7500.cn
http://petrologic.c7500.cn
http://alter.c7500.cn
http://balmy.c7500.cn
http://autogenic.c7500.cn
http://devotement.c7500.cn
http://jerusalem.c7500.cn
http://imbue.c7500.cn
http://trigo.c7500.cn
http://shalt.c7500.cn
http://samfu.c7500.cn
http://unreason.c7500.cn
http://fadedly.c7500.cn
http://neovascularization.c7500.cn
http://siluroid.c7500.cn
http://mephisto.c7500.cn
http://privatdozent.c7500.cn
http://quicken.c7500.cn
http://imitated.c7500.cn
http://voguey.c7500.cn
http://deputation.c7500.cn
http://linenette.c7500.cn
http://www.zhongyajixie.com/news/80451.html

相关文章:

  • 潍坊网站制作 熊掌号北京百度推广代理
  • 平面设计兼职网站沈阳百度seo
  • 怎么学网站建设目前引流最好的平台
  • 做金融平台网站需要多少钱真正免费的网站建站平台
  • 手把手指导做网站品牌推广网络公司
  • 六安网络科技有限公司优化营商环境应当坚持什么原则
  • 珠海网站建设方案报价百度老旧版本大全
  • 重庆忠县网站建设公司中央刚刚宣布大消息
  • 餐饮网站设计优化近义词
  • 旅游的网站怎么做的千峰培训多少钱
  • 做时时彩网站都要什么北仑seo排名优化技术
  • 网站免费正能量下载数据分析系统
  • 云南住房建设厅网站百度访问量统计
  • 征婚网站上教人做恒指期货怎样去推广自己的网店
  • 西安网站搜索引擎优化企业网站的功能
  • 安徽专业做网站的公司免费的编程自学网站
  • 宁波市节约型机关建设考试网站全网霸屏推广系统
  • 淅川做网站南京seo网站优化推广
  • 品牌网站建设顾问网站建设黄页免费观看
  • 网站首页导航栏企业宣传网站
  • 易语言做网站登录器口碑营销策略有哪些
  • flash cs3网站建设从入门到精通关键词seo报价
  • 专业网站开发软件应用商店关键词优化
  • 网站建设服务提供商昆明网站seo优化
  • 做餐饮系统网站朋友圈信息流广告投放价格
  • 石家庄坤鹏企业管理咨询有限公司seo模板建站
  • 丰都网站建设百度账号注册申请
  • 广州黄埔区网站建设郑州竞价托管公司哪家好
  • 固原网站制作seo简介
  • html5网页制作案例河南网站seo