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

怎样利用网站做引流互联网营销怎么赚钱

怎样利用网站做引流,互联网营销怎么赚钱,ppt下一页,wordpress后台汉语hi,bro—— 目录 5、 链表分割 6、 链表的回文结构 7、 相交链表 8、 环形链表 【思考】 —————————————— DEAD POOL —————————————— 5、 链表分割 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), …

hi,bro——

目录

5、 链表分割

6、 链表的回文结构

7、 相交链表

8、 环形链表

【思考】

                 —————————————— DEAD POOL ——————————————


5、 链表分割

/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
#include <functional>
class Partition {
public:ListNode* partition(ListNode* pHead, int x){//创建新的大小链表ListNode* lessHead,*lessTail;lessHead=lessTail=(ListNode*)malloc(sizeof(ListNode));ListNode* greaterHead,*greaterTail;greaterHead=greaterTail=(ListNode*)malloc(sizeof(ListNode));//创建新的头结点遍历数组ListNode* pcur=pHead;while(pcur){if(pcur->val<x){//尾插到小链表lessTail->next=pcur;lessTail=lessTail->next;}else{//尾插到大链表greaterTail->next=pcur;greaterTail=greaterTail->next;}pcur=pcur->next;}//大小链表首尾相连lessTail->next=greaterHead->next;greaterTail->next=NULL;ListNode* ret=lessHead->next;free(lessHead);free(greaterHead);lessHead=NULL;greaterHead=NULL;return ret;}
};

6、 链表的回文结构

在链表中不可回找,但是数组可以回找,所以我们可以把链表中的数据放到数组中。

思路1:创建新数组,遍历原链表,将链表中的值放到数组中,然后在数组中判断是否为回文结构。

因为题目中提前对链表的长度进行了限制,若不限制,空间复杂度为O(N)就不符合题目的条件了
/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public:bool chkPalindrome(ListNode* A) {int arr[900]={0};ListNode* pcur=A;int i=0;//将链表中的数据赋给数组while(pcur){arr[i++]=pcur->val;pcur=pcur->next;}//i为链表中结点的个数//判断数组中的值是否为回文结构int left=0;int right=i-1;while(left<right){if(arr[left]!=arr[right]){return false;}left++;right--;}return true;}
};

思路2:反转链表,这种方法的时间复杂度为O(N),空间复杂度为O(1)

1)找原链表的中间结点,“快慢指针”;

2)将中间结点及之后的结点进行反转;

3)从原链表的头结点和新链表的头结点开始遍历比较。

/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public://找中间结点ListNode* findMidNode(ListNode* phead){ListNode* slow,*fast;slow=fast=phead;while(fast&&fast->next){slow=slow->next;fast=fast->next->next;}return slow;}//反转链表ListNode* reverseList(ListNode* phead){ListNode* n1,*n2,*n3;n1=NULL;n2=phead;n3=n2->next;while(n2){n2->next=n1;n1=n2;n2=n3;if(n3)n3=n3->next;}return n1;}bool chkPalindrome(ListNode* A) {//1.找中间结点ListNode* mid=findMidNode(A);//2.反转链表ListNode* right=reverseList(mid);//3.遍历比较ListNode* left=A;while(right){if(left->val!=right->val)return false;left=left->next;right=right->next;}return true;}
};

7、 相交链表

思路:1)判断两个链表是否相等

           2)返回两个单链表相交的起始结点

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {ListNode* l1=headA;ListNode* l2=headB;int countA=0;int countB=0;//求两个链表的长度while(l1){countA++;l1=l1->next;}while(l2){l2=l2->next;countB++;}//求链表长度差值的绝对值int gap=abs(countA-countB);//判断哪个是长短链表ListNode* longList=headA;ListNode* shortList=headB;if(countA<countB){longList=headB;shortList=headA; }//让两个链表在同一起跑线while(gap--){longList=longList->next;}//判断两个链表是否相交while(longList&&shortList){//相交if(longList==shortList){return longList;}longList=longList->next;shortList=shortList->next;}//不相交return NULL;
}

8、 环形链表

思路: 

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
bool hasCycle(struct ListNode *head) {ListNode* slow=head;ListNode* fast=head;while(fast&&fast->next){slow=slow->next;fast=fast->next->next;if(slow==fast){return true;}}return false;
}

【思考】

头好痒,感觉要长脑子了


完—— 

Relaxing Time !

         —————————————— DEAD POOL ——————————————

https://t3.kugou.com/song.html?id=c35Fp66CPV2icon-default.png?t=N7T8https://t3.kugou.com/song.html?id=c35Fp66CPV2

能力越大越没责任 

Bye ~~~ 

http://www.wangmingla.cn/news/48182.html

相关文章:

  • 传奇世界网页版平台通州优化公司
  • 怎么做阿里巴巴国际网站首页全网整合营销公司
  • 广东最新疫情今天新增伟哥seo博客
  • wap网站制作教程免费网站做seo
  • 宜昌今日头条新闻长沙网站优化对策
  • 买下云服务器怎么做网站苏州网站维护
  • wordpress更改首页模板aso安卓优化
  • wordpress的FTP帐号长春seo结算
  • 中国电信 网站备案东莞seo建站推广费用
  • 零下一度网站建设推广网络推广平台
  • wordpress 多站点 插件宁德市住房和城乡建设局
  • 怎么做类似淘宝一样的网站创建网站的基本流程
  • 银河星宇 网站建设百度关键词优化多少钱
  • 网站前端是什么网站建设费用明细表
  • 西地那非片怎么服用最佳优化大师专业版
  • 需要做网站的企业资源军事新闻最新消息今天
  • 怎么建立自己的网站平台多少钱推广方案的内容有哪些
  • 二手房发布网站怎么做浙江疫情最新情况
  • 在阿里云做视频网站需要什么专业培训机构
  • 娄底网站建设优化企业外链发布平台大全
  • 形象设计师培训网课seo主管招聘
  • 怎么才能百度做网站腾讯会议多少钱一个月
  • 商丘做网站公司百度快照和广告的区别
  • 网站后台文章编辑不了500强企业seo服务商
  • 网站做315认证百度推广开户费用多少
  • 宁德城乡建设部网站营销公司排行
  • 遵义网站建设价格简述常用的网络营销方法
  • 哪些网站可以做招生百度极速版下载安装最新版
  • 河北网站建设推广公司十种营销方法
  • 新乡市做网站直销系统网站网络营销方案设计范文