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

沈阳做网站的公司有哪些指数基金什么意思

沈阳做网站的公司有哪些,指数基金什么意思,鞍山诺亚人才网,做字幕模板下载网站有哪些// 单链表 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.ds6.com.cn/news/99175.html

相关文章:

  • 宁波正规网站seo公司企业营销型网站策划
  • java做博客网站有哪些功能关键词排名代做
  • wordpress企业免费国人主题嘉峪关seo
  • 克隆wordpress网页网站关键字优化
  • 广西建设网电子证查询打印网站排名优化化快排优化
  • 河南政府采购网泰安seo培训
  • 一流专业建设网站武汉seo系统
  • 泰安有几个区廊坊关键词优化平台
  • web前端就是做网站么谷歌seo最好的公司
  • 网站建设昆明网络公司常用的seo工具的是有哪些
  • 电子商务网站建设实训体会网络精准推广
  • 无锡新区网站制作推广app大全
  • 鲜花网站建设规划做推广哪个平台效果好
  • 郑州动力无限网站建设小程序商城制作一个需要多少钱
  • 网络营销服务有限公司百度seo收费
  • 做兼职的网站都有哪些工作淄博seo
  • 免费咨询律师在线微信福建seo
  • 那些做seo的网站短视频营销的优势
  • 上海哪个网站专门做宝宝宴的网站优化推广平台
  • 浦项建设公司员工网站正规app推广
  • 南京网站设计公司济南兴田德润优惠吗短视频代运营费用明细
  • 山东省建设厅职业资格注册中心网站常州网站建设书生商友
  • 平阳住房和城乡规划建设局网站百度竞价软件哪个好
  • 落地页网站建设win优化大师有用吗
  • 网站需要条件seo站外推广
  • 微信推广工具深圳优化公司排名
  • 本地电脑独立ip做网站岳阳seo
  • 哈尔滨模板建站品牌优秀的品牌策划案例
  • 网站售后服务内容北京seo顾问
  • 海外红人营销推广郑州seo顾问