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

百度网站网址是什么公司推广渠道有哪些

百度网站网址是什么,公司推广渠道有哪些,昆明网站制作费用,威海做网站的公司哪家好理论 链表的增删操作时间复杂度O(1),查询时间复杂度O(n),因为要从头结点开始。使用场景和数据完全相反 链表的储存地址是不连续的。也和数组不同。 移除链表元素 利用虚拟头结点可以同意操作。不然删除头结点需要额外写。 记得返回的是虚拟头结点的next而不是虚拟头结点retu…

理论

链表的增删操作时间复杂度O(1),查询时间复杂度O(n),因为要从头结点开始。使用场景和数据完全相反
链表的储存地址是不连续的。也和数组不同。

移除链表元素

利用虚拟头结点可以同意操作。不然删除头结点需要额外写。
记得返回的是虚拟头结点的next而不是虚拟头结点return dummyhead。哈哈哈

class Solution {
public:ListNode* removeElements(ListNode* head, int val) {ListNode* dummyhead = new ListNode(60);dummyhead->next=head;ListNode* cur=dummyhead;while(cur->next!=NULL){if(cur->next->val == val){ListNode* temp=cur->next;cur->next = cur->next->next;delete temp;}else{cur=cur->next;}}return dummyhead->next;}
};

设计链表

总是忘记判定插入或者删除的位置是否有效。

class MyLinkedList {
public:struct ListNode {int val;ListNode *next;ListNode(int val) : val(val), next(nullptr) {}};MyLinkedList() {dummyhead=new ListNode(0);size=0;}int get(int index) {if(index>size-1)return -1;ListNode* cur=dummyhead->next;for(int i=0;i<index;i++){cur=cur->next;}return cur->val;}void addAtHead(int val) {ListNode* head= new ListNode(val);head->next=dummyhead->next;dummyhead->next=head;size++;}void addAtTail(int val) {if(size==0) dummyhead->next=new ListNode(val);else{ListNode* cur=dummyhead->next;while(cur->next != NULL){cur=cur->next;}cur->next= new ListNode(val);}size++;}void addAtIndex(int index, int val) {if(index>size) return;ListNode* cur=dummyhead;for(int i=0;i<index;i++){cur=cur->next;}ListNode* temp=new ListNode(val);temp->next=cur->next;cur->next=temp;size++;}void deleteAtIndex(int index) {if(index>=size) return;ListNode* cur=dummyhead;for(int i=0;i<index;i++){cur=cur->next;};ListNode* temp=cur->next;cur->next=cur->next->next;delete temp;size--;}//void printLinkedList(){//}
private:int size;ListNode* dummyhead;
};

翻转链表

中间过程想到了用三个指针,双指针+储存临时下一个的指针。
但是开头和结尾的处理过程没想出来。
直接让pre=head,这样的话还得加上head->next=nullptr才表示一条链表结束了。
所以让pre=null就不用特殊处理开头和结尾了。

    ListNode* reverseList(ListNode* head) {//if(head->next==nullptr) return nullptr;//ListNode* dummyhead= new ListNode(0);//dummyhead->next=head;//ListNode* pre=head;//ListNode* cur=pre->next;//ListNode* next=cur->next;//cur->next=pre;//head=reversal(cur,next);//return head;if(head==nullptr) return nullptr;ListNode* pre=nullptr;ListNode* cur=head;while(cur!=nullptr){ListNode* next=cur->next;cur->next=pre;pre=cur;cur=next;}return pre;}

快忘记递归怎么写啦,就是递归套递归。

class Solution {
private:ListNode* reversal(ListNode* pre,ListNode* cur){if(cur==nullptr) return pre;ListNode* temp=cur->next;cur->next=pre;return reversal(cur,temp);}
public:ListNode* reverseList(ListNode* head) {ListNode* pre=nullptr;ListNode* cur=head;return reversal(pre,cur);}};
http://www.dt0577.cn/news/22595.html

相关文章:

  • 做3个网站需要多大的服务器企业为何选择网站推广外包?
  • 陶瓷网站模板下载seo+网站排名
  • html网站源码排名app
  • 哪几个小说网站做网编拿的钱多策划营销
  • 婚介网站方案b2b免费发布信息网站
  • 网站建设和运营站长查询
  • 商城系统 WordPress链接优化方法
  • 网站建设销售销售流程图seo计费系统源码
  • 做网站专题怎样添加微博网络整合营销方案ppt
  • 福州软件园百度关键词在线优化
  • adobe可以做网站吗盛大游戏优化大师
  • 南昌建站方案线上广告接单平台
  • 石家庄企业网站制作电商培训内容
  • 网站建设策划结束语杭州seo排名优化
  • 做站群什么样的算是违法网站济南seo网络优化公司
  • 贵州做团队培训的网站怎么创建网站快捷方式到桌面
  • 博客网站模板关键词排名查询工具免费
  • 杭州做网站公司排名seo工具下载
  • 电子商务网站建设百度文库seo搜索引擎优化简历
  • 嘉兴网站建设公司重庆森林为什么叫这个名字
  • 网站做排名最能打动顾客的十句话
  • wordpress 主题 瀑布流关键词seo培训
  • 深圳商城网站短视频营销优势
  • 池州海绵城市建设官方网站房地产市场现状分析
  • 佛系wordpressseo优化分析
  • wordpress无法上传应用商店搜索优化
  • 绵阳哪个网站做外卖做的好手机网站百度关键词排名查询
  • 怎么在电脑上用手机app软件仁茂网络seo
  • 模板外贸网站建设营销活动推广策划
  • 佛山外英语网站制作常德网站优化公司