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

手机做网站对比路由器做网站安顺市住房与城乡建设局网站

手机做网站对比路由器做网站,安顺市住房与城乡建设局网站,自己在家做电商,手机网站建设项目题目链接 反转链表:206. 反转链表 - 力扣(LeetCode)K个一组翻转链表:25. K 个一组翻转链表 - 力扣(LeetCode)回文链表:234. 回文链表 - 力扣(LeetCode) 实现思路 代码实…

题目链接

  • 反转链表:206. 反转链表 - 力扣(LeetCode)
  • K个一组翻转链表:25. K 个一组翻转链表 - 力扣(LeetCode)
  • 回文链表:234. 回文链表 - 力扣(LeetCode)

实现思路

代码实现

  • 反转链表:
/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
class Solution {
public:ListNode* reverseList(ListNode* head) {ListNode* pre = nullptr;ListNode* cur = head;while(cur) {ListNode* next = cur -> next;cur -> next = pre;pre = cur;cur = next;}return pre;}
};
  • K个一组翻转链表
/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
class Solution {
public:vector<ListNode*> reverse(ListNode* head, ListNode* next) {ListNode* pre = next;ListNode* cur = head;while (cur != next) {ListNode* nextNode = cur -> next;cur -> next = pre;pre = cur;cur = nextNode;}return {pre, head}; // pre是反转之后的头节点,head是反转之后的尾节点}ListNode* reverseKGroup(ListNode* head, int k) {int cnt = 0;ListNode* cur = head;ListNode* preHead = new ListNode(-1);preHead -> next = head;ListNode* pre = preHead;while (cur) {cnt++;if (cnt % k == 0) {cnt = 0;vector<ListNode*> res = reverse(pre->next, cur->next);pre->next = res[0];cur = res[1];pre = cur;}cur = cur -> next;}return preHead -> next;}
};
  • 回文链表
/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
class Solution {
public:ListNode* reverse(ListNode* head) {ListNode* pre = nullptr;ListNode* cur = head;while (cur) {ListNode* next = cur -> next;cur -> next = pre;pre = cur;cur = next;}return pre;}bool isPalindrome(ListNode* head) {if (head -> next == nullptr) return true;ListNode* preHead = new ListNode();preHead -> next = head;ListNode* slow = preHead;ListNode* fast = preHead;while (fast != nullptr && fast -> next != nullptr) {slow = slow -> next;fast = fast -> next -> next;}// 反转slow->next到tail的部分ListNode* head1 = slow -> next;head1 = reverse(head1);ListNode* cur = head;ListNode* cur1 = head1;while (cur1) {if (cur -> val != cur1 -> val) {return false;}cur = cur -> next;cur1 = cur1 -> next;}return true;}
};

http://www.dtcms.com/a/448350.html

相关文章:

  • 自己做头像网站跳转到另一个网站怎么做
  • 东莞企业免费建站教学网站开发视频
  • 网站专业技能培训机构东莞市建设工程交易中心网
  • 深圳网站建设服务公常见门户网站的基本功能
  • 建筑行业网站模版百度蜘蛛网站排名
  • 织梦网站安装教程视频教程网站建设微信小程序开发
  • 建设银行理财产品网站电费公众号开发
  • 物流网站开发公司wordPress主题模板站
  • 移动网站用什么建设旅游网站开发的背景及意义
  • 如何提高网站的点击率想建一个网站怎么做
  • 国内贸易在那个网站上做阳泉网站设计
  • 厦门做网站公司排名站长基地
  • 分类网站发布信息有生意做吗产品软文范例100字
  • 盐城做企业网站多少钱刚做优化的网站什么能更新
  • 企业建设网站的目的是企业免费邮箱注册申请
  • 聊城手机网站建设公司乐清做网站的公司有哪些
  • 做美妆网站名称如何搭建网站的支付接口
  • 怎么创建属于自己的网站网站推广--html关键词代码解说
  • 如何在后台做网站分页安徽省建设监理协会新网站
  • 天津公司网站怎样制作可以免费发广告的网站有哪些
  • 网站交互图片怎么做建一个网站需要什么条件
  • 各大网站投稿方式wordpress有问题
  • 如何用一个域名做多个网站株洲做网站的公司
  • 江西网站开发方案国家认可的赚钱游戏
  • 图片手机网站建设中国企业名录黄页
  • 做网站用笔记本做服务器网站平台有哪些类型
  • 建网站收费吗工长网站开发
  • 网站付款链接怎么做2021年天津教师招聘信息
  • 免费服务器永久成都网站建设 seo
  • 建设银行怎么网站定制短信通知郑州外贸网站建设商家