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

文件服务器网站搭建教程网站那种推广链接怎么做

文件服务器网站搭建教程,网站那种推广链接怎么做,自治区住房和城乡建设厅网站,如何做带后台的网站目录 #x1f4a1;重排链表 题目描述 方法一#xff1a; 方法二#xff1a; #x1f4a1;旋转链表 题目描述 方法#xff1a; #x1f4a1;反转链表|| 题目描述 方法#xff1a; #x1f4a1;总结 #x1f4a1;重排链表 题目描述 给定一个单链表 L 的头节… 目录 重排链表 题目描述 方法一 方法二 旋转链表 题目描述 方法 反转链表|| 题目描述 方法 总结 重排链表 题目描述 给定一个单链表 L 的头节点 head 单链表 L 表示为 L0 → L1 → … → Ln-1 → Ln  请将其重新排列后变为 L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → … 不能只是单纯的改变节点内部的值而是需要实际的进行节点交换。 提示 链表的长度范围为 [1, 5 * 104]1 node.val 1000 方法一 将链表的每一个节点存在数组里然后用下标访问的方式交叉连接。 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/typedef struct ListNode ListNode; void reorderList(struct ListNode* head){if(head-nextNULL||head-next-nextNULL)return;ListNode* arr[50001];ListNode* curhead;int n0;while(cur){arr[n]cur;curcur-next;n;}int i0;int jn-1;while(ij){arr[i]-nextarr[j];i;arr[j]-nextarr[i];j--;}arr[i]-nextNULL;} 方法二 可以先用快慢指针的方法找到链表的中间节点然后将中点后的链表翻转成一个新的链表最后将这个新链表和原链表切割掉中间节点之后的链表合并成一个新的链表合并方式是交叉合并。 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/typedef struct ListNode ListNode; ListNode* MiddleNode(ListNode* head) {ListNode* fasthead;ListNode* slowhead;while(fast!NULLfast-next!NULL){fastfast-next-next;slowslow-next;}return slow; } ListNode* ReverseList(ListNode* head) {ListNode* pheadNULL;ListNode* curhead;while(cur){ListNode* tmpcur-next;//注意先后顺序cur-nextphead;pheadcur;curtmp;}return phead; } void reorderList(struct ListNode* head){ListNode* midMiddleNode(head);ListNode* pheadReverseList(mid-next);mid-nextNULL;ListNode* curhead;while(phead){ListNode* nextcur-next;cur-nextphead;ListNode* tmp phead-next;phead-nextnext;pheadtmp;curcur-next-next;}} 旋转链表 题目描述 给你一个链表的头节点 head 旋转链表将链表每个节点向右移动 k 个位置。 提示 链表中节点的数目在范围 [0, 500] 内-100 Node.val 1000 k 2 * 109 方法 要求每个节点向右移动k位置其实就是将倒数k个结点接在头节点之前倒数第k个结点成为新的头节点但是这里需要对k进行处理因为k可能大于链表长度所以kk%len还有一个需要注意的就是当klen时是不需要进行任何操作的直接返回头节点就可以了。 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ typedef struct ListNode ListNode; struct ListNode* rotateRight(struct ListNode* head, int k) {if(headNULL||k0)return head;ListNode* curhead;ListNode* prevhead;ListNode* rethead;int l0;while(ret){retret-next;l;}kk%l;if(k0)return head;while(k--){curcur-next;}while(cur-next){curcur-next;prevprev-next;}ListNode* Nextprev-next;cur-nexthead;prev-nextNULL;return Next; } 反转链表|| 题目描述 给你单链表的头指针 head 和两个整数 left 和 right 其中 left right 。请你反转从位置 left 到位置 right 的链表节点返回 反转后的链表 。 提示 链表中节点数目为 n1 n 500-500 Node.val 5001 left right n 方法 我的方法就是将区间[left,right]之间的结点翻转然后与原来区间前后的结点重新连接起来。 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ typedef struct ListNode ListNode; struct ListNode* reverseList(struct ListNode* head,struct ListNode* tail) {ListNode*pheadNULL;//新的头ListNode*curhead;while(cur!tail)//遍历原链表{ListNode*nextcur-next;//保存下一个节点的地址避免丢失cur-nextphead;pheadcur;//更新头节点curnext;//继续遍历}return phead; } struct ListNode* reverseBetween(struct ListNode* head, int left, int right) {ListNode* cur1head;ListNode* cur2head;int cnt1;while(cntleft-1){cur1cur1-next;cur2cur2-next;cnt;}while(cntright){cur2cur2-next;cnt;}ListNode* tailNULL; if(cur2!NULL)tailcur2;if(left1)headreverseList(cur1,cur2);elsecur1-nextreverseList(cur1-next,cur2);while(cur1-next){cur1cur1-next;}cur1-nexttail;return head; } 总结 链表相关的题目还是要注意细节结点之间的切割与连接要特别仔细不然任意造成空结点或者成环导致死循环。
http://www.tj-hxxt.cn/news/223844.html

相关文章:

  • 浙江网站建设平台网络设计是啥
  • 如何在网站做引流网络推广服务投诉
  • 蜜淘app在那个网站做的北京网站运营优化公司
  • 学校网站建设论文开发公司交房流程及注意事项
  • js检测网站是否能打开注册安全工程师注册管理系统
  • 做游戏网站主页的素材大庆网站建设优化
  • 兰州网站外包产品设计培训机构哪家好
  • 网站管理员中心做一个网站都需要什么
  • wordpress快速仿站用织梦做网站能练技术吗
  • 做钓鱼网站视频教程做头像网站静态
  • 做编程的网站有哪些内容国外做无纺布的网站
  • 10个国内建筑网站副国级人员名单
  • 成都电商网站建设wordpress适用linux
  • 网站seo方案策划书同一个域名可以做几个网站吗
  • 云南个旧建设局网站wordpress 无法自动更新
  • 自己做网站买东西做商城网站带宽
  • 什么网站可以做时间加减公众号开发退款步骤
  • 手机版免费申请微网站wordpress写作主题
  • 校园内部网站建设方案北京大型商场
  • 网站是如何做的好遵义网络推广软文
  • 网站推广的方式和管理方法包头建设厅官方网站
  • 东莞网站开发前三强福建省建设注册中心网站
  • 做网站page只让搜索引擎查看文章wordpress
  • 烟台做网站的公司济南 网站建设
  • 个人电脑做网站违法吗网站专用app
  • 餐饮行业做网站的好处深圳网站设计官网
  • 网站建设收费标准讯息贵阳做网站多少钱
  • 网站集群建设中标潍坊建设网站公司电话
  • 建医疗网站步骤道滘镇做网站
  • 南京江浦做网站设计的公司wordpress产品页面模板