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

松江做营销网站站长工具推荐

松江做营销网站,站长工具推荐,摄影设计说明万能模板,led行业网站建设方案// 单链表 struct ListNode {int val; // 节点上存储的元素ListNode *next; // 指向下一个节点的指针ListNode(int x) : val(x), next(NULL) {} // 节点的构造函数 };ListNode* head new ListNode(5); 重要方法:虚拟头节点 个人方法:指针转为数组…
// 单链表
struct ListNode {int val;  // 节点上存储的元素ListNode *next;  // 指向下一个节点的指针ListNode(int x) : val(x), next(NULL) {}  // 节点的构造函数
};ListNode* head = new ListNode(5);

重要方法:虚拟头节点 

个人方法:指针转为数组(详见4、5)

1.移除链表元素

203. 移除链表元素 - 力扣(LeetCode)
方法一:

ListNode* removeElements(ListNode* head, int val) {// 删除头结点while (head != NULL && head->val == val) { // 注意这里不是ifListNode* tmp = head;head = head->next;delete tmp;}// 删除非头结点ListNode* cur = head;while (cur != NULL && cur->next!= NULL) {if (cur->next->val == val) {ListNode* tmp = cur->next;cur->next = cur->next->next;delete tmp;} else {cur = cur->next;}}return head;
}

方法二(虚拟头节点):

ListNode* removeElements(ListNode* head, int val) {ListNode* dummyHead = new ListNode(0); // 设置一个虚拟头结点dummyHead->next = head; // 将虚拟头结点指向head,这样方便后面做删除操作ListNode* cur = dummyHead;while (cur->next != NULL) {if(cur->next->val == val) {ListNode* tmp = cur->next;cur->next = cur->next->next;delete tmp;} else {cur = cur->next;}}head = dummyHead->next;delete dummyHead;return head;
}

2.设计链表

707. 设计链表 - 力扣(LeetCode)

3.反转链表

206. 反转链表 - 力扣(LeetCode)

ListNode* reverseList(ListNode* head) {ListNode* dummy = new ListNode();ListNode* cur;while(head != nullptr){cur = head;head = head->next;cur->next = dummy->next;dummy->next = cur;}return dummy->next;
}

4.链表相交

面试题 02.07. 链表相交 - 力扣(LeetCode)

ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {// 转化为指针数组vector<ListNode*> a, b;while(headA != NULL){a.push_back(headA);headA = headA->next;}while(headB != NULL){b.push_back(headB);headB = headB->next;}int mini = min(a.size(), b.size());ListNode* res = NULL;for(int i = 1; i <= mini; i ++){if(a[a.size() - i] == b[b.size() - i]) res = a[a.size() - i];}return res;
}

 5.环形链表

142. 环形链表 II - 力扣(LeetCode)

方法一:暴力

ListNode *detectCycle(ListNode *head) {vector<ListNode*> array;ListNode* res = NULL;while(head != NULL){for(int i = 0; i < array.size(); i ++ ){if(array[i] == head) return head;}array.push_back(head);head = head->next;}return res;
}

方法二:双指针

ListNode *detectCycle(ListNode *head) {ListNode* fast = head;ListNode* slow = head;while(fast != NULL && fast->next != NULL) {slow = slow->next;fast = fast->next->next;// 快慢指针相遇,此时从head 和 相遇点,同时查找直至相遇if (slow == fast) {ListNode* index1 = fast;ListNode* index2 = head;while (index1 != index2) {index1 = index1->next;index2 = index2->next;}return index2; // 返回环的入口}}return NULL;
}
http://www.shuangfujiaoyu.com/news/26067.html

相关文章:

  • 哪个网站能上传自己做的简历新人跑业务怎么找客户
  • 怎么利用招聘网站做薪酬调查seo公司推广宣传
  • 网站建设迅雷群排名优化软件
  • 沧州建设银行招聘网站盐城seo培训
  • 网页设计与网站开发的总结安装百度一下
  • 视频号怎么经营seo查询百科
  • 网站设计验收商城推广软文范文
  • 仿造网站用侵权吗在线建站网页制作网站建设平台
  • 创建全国文明城市建议简短优化网站
  • 架构图在什么网站可以做公司企业网站建设
  • 建站之星做出的网站不安全如何制作网站最简单的方法
  • 什么网站做任务赚钱吗万能搜索网站
  • jsp网站怎么做品牌运营总监
  • 常州h5网站建设无锡百度推广代理公司
  • 网站模板佳好乐云seo能打开任何网站浏览器
  • 毕业论文网站开发的参考文献nba最新交易汇总实时更新
  • 东莞seo技术培训西安seo优化
  • 两学一做知识竞答网站电商运营公司简介
  • 厦门有做网站建设温州网站建设优化
  • 广州网站建设团队搜索引擎优化seo多少钱
  • 怎么把做的网页放入网站seo干什么
  • wordpress 域名邮箱设置关键词优化推广排名多少钱
  • 做网站推广和头条推广网络营销和传统营销有什么区别
  • 网站如何做美工移动建站模板
  • 运营网站需要多少钱app营销推广方案
  • 黄山网站建设百度引擎
  • 台州做网站的公司品牌形象推广
  • 计算机网络技术电商网站建设与运营品牌建设的五个要素
  • 即墨网站建设公司百度竞价推广的技巧
  • 网站建设合同书下载百度无广告搜索引擎