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

什么样的网站需要数据库佛山网站建设推荐

什么样的网站需要数据库,佛山网站建设推荐,网站推广外包公司哪家好,长春建站模板厂家1. 要找俩个数使其相加等于一个数#xff0c;那么俩个数从头尾出发#xff0c;先动一边#xff0c;假设是尾先动#xff0c;一开始俩个数相加大于sum#xff08;小于的话就动头#xff09;#xff0c;那么总有一时刻俩数相加小于sum#xff0c;则就在那一刻停下来那么俩个数从头尾出发先动一边假设是尾先动一开始俩个数相加大于sum小于的话就动头那么总有一时刻俩数相加小于sum则就在那一刻停下来然后动头那一边去逼近sum最坏情况就是俩个数字相遇了时间复杂度就为ON 2. 可以通过一直替换T(n-1)使其变成常数每次降低一次就为有里面减一到外面来因为时间复杂度看的是最大级所以是0N 3 . 思路一 在开俩个数组去存放数据一个存放k个一个存放numsSize-k个先把它们分隔开然后再都放进原来的数组里就可以达到要求  代码实现 void rotate(int* nums, int numsSize, int k) {int k1k%numsSize;int* a(int*)malloc(sizeof(int)*(numsSize-k1));int* b(int*)malloc(sizeof(int)*k1);for(int i0;inumsSize-k1;i){a[i]nums[i];}for(int j0;jk1;j){b[j]nums[numsSize-k1j];}for(int z0;zk1;z){nums[z]b[z];}for(int t0;tnumsSize-k1;t){nums[tk1]a[t];} } 思路二 先转置整个数组数字然后在转置k-1个元素最后转置k到numsSize的数组数字这样就调换了以k分成俩边数组的位置 代码实现 void reverse(int* nums, int begin, int end) {while (begin end){int tmp nums[begin];nums[begin] nums[end];nums[end] tmp;begin;--end;} }// 三趟逆置倒的思路 void rotate(int* nums, int numsSize, int k) {if (k numsSize){k % numsSize;}reverse(nums, 0, numsSize - 1);reverse(nums, 0, k - 1);reverse(nums, k, numsSize - 1); }4. 思路 要找到确失的数字可以把这个数全部加起来然后再重新创建一个不却数字的数组把这个也加起来然后俩个相减得到值就是缺少的值 代码实现 int missingNumber(int* nums, int numsSize){int b0;int c0;int* a(int*)malloc(sizeof(int)*(numsSize1));for(int i0;inumsSize;i){a[i]i;}for(int i0;inumsSize;i){bnums[i];}for(int i0;inumsSize;i){ca[i];}return c-b; }5. 思路一 总数-k为正数第几个把总数算出来在和k相减就可以知道在哪一个位置 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ int gettree(struct ListNode* head) {int size0;while(head){headhead-next;size;}return size; }int kthToLast(struct ListNode* head, int k){struct ListNode* curhead;int agettree(head);int ca-k;while(c--){curcur-next;}return cur-val; }思路二 快慢指针先让fast走k步后让fast和slow一起走slow一共会走总数-k步也可以走到对应位置 class Solution { public:ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {struct ListNode* slow pListHead;struct ListNode* fast slow;while (k--){if (fast)fast fast-next;elsereturn NULL;}while (fast){slow slow-next;fast fast-next;}return slow;} }; 6. 思路 1 快慢指针先找到中间结点然后逆置中间后面的结点最后跟前半部分对比 代码实现 这一步是找中间结点 while(fastfast-next){slowslow-next;fastfast-next-next;} 这一步是逆置中间后面的结点然后把连接方向改变 ListNode* curNULL;ListNode* nextA;while(slow){nextslow-next;slow-nextcur;curslow;slownext;}把前半部分和后半部分进行对比 nextA;while(cur){if(next-val!cur-val){return false;}nextnext-next;curcur-next;}return true; 总代码 /* struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {} };*/ class PalindromeList { public:bool chkPalindrome(ListNode* A) {ListNode* fastA;ListNode* slowA;while(fastfast-next){slowslow-next;fastfast-next-next;}ListNode* curNULL;ListNode* nextA;while(slow){nextslow-next;slow-nextcur;curslow;slownext;}nextA;while(cur){if(next-val!cur-val){return false;}nextnext-next;curcur-next;}return true;} }; 思路二 可以把值都放进数组里面但是如果题目没告诉链表最大值就不能使用这个方法 放进数组后把头尾的值取出来进行对比一直往中间 代码实现 class PalindromeList { public:bool chkPalindrome(ListNode* A) {// write code hereint a[900] { 0 };ListNode* cur A;int n 0;//保存链表元素while (cur){a[n] cur-val;cur cur-next;}//判断数组是否为回文结构int begin 0, end n - 1;while (begin end){if (a[begin] ! a[end])return false;begin;--end;}return true;} }; 7. 思路 因为俩个链表长度有可能不一样长所以需要让长的链表先走使得出发时俩个俩个链表等长 就可以找到最后一个相等的结点(不是找第一个相等的而是找最后一个) 代码实现 计算俩个链表计数 int a0;int b0;struct ListNode* aaheadA;struct ListNode* bbheadB;while(aa){a;aaaa-next;}while(bb){b;bbbb-next;} 找到俩个链表的长的哪一个可以用假设法可以节省很多步骤先假设1大2小不是就调整非常方便 /*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/ struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {int a0;int b0;struct ListNode* aaheadA;struct ListNode* bbheadB;while(aa){a;aaaa-next;}while(bb){b;bbbb-next;}int ca-b0?a-b:b-a;struct ListNode* long1headA;struct ListNode* short1headB;if(ab){long1headB;short1headA;}while(c--){long1long1-next;}while(short1long1){if(short1long1){return long1;}else{long1long1-next;short1short1-next;}}return NULL; }8. 思路 因为要复制出一个与原链表一样的东西出来所以可以在每个结点后面跟一个新结点 代码实现 1.创建新结点连在原链表的后面并把val值也复制过去 struct Node* curhead;while(cur){struct Node* copy(struct Node*)malloc(sizeof(struct Node));copy-valcur-val;copy-nextcur-next;cur-nextcopy;curcopy-next;} 2 .把random的也复制过去 curhead;struct Node* copyheadNULL;struct Node* copytailNULL;while(cur){struct Node* copycur-next;struct Node* nextcopy-next;if(cur-randomNULL){copy-randomNULL;}else{copy-randomcur-random-next;}curnext;} 3.把复制的链表从原链表上拆下来 curhead;while(cur){struct Node* copycur-next;struct Node* nextcopy-next;if(copytailNULL){copyheadcopytailcopy;}else{copytail-nextcopy;copytailcopytail-next;}cur-nextnext;curnext;}return copyhead; /*** Definition for a Node.* struct Node {* int val;* struct Node *next;* struct Node *random;* };*/struct Node* copyRandomList(struct Node* head) {struct Node* curhead;while(cur){struct Node* copy(struct Node*)malloc(sizeof(struct Node));copy-valcur-val;copy-nextcur-next;cur-nextcopy;curcopy-next;}curhead;struct Node* copyheadNULL;struct Node* copytailNULL;while(cur){struct Node* copycur-next;struct Node* nextcopy-next;if(cur-randomNULL){copy-randomNULL;}else{copy-randomcur-random-next;}curnext;}curhead;while(cur){struct Node* copycur-next;struct Node* nextcopy-next;if(copytailNULL){copyheadcopytailcopy;}else{copytail-nextcopy;copytailcopytail-next;}cur-nextnext;curnext;}return copyhead; }
http://www.pierceye.com/news/659163/

相关文章:

  • 小程序价格为什么比网站建设高自定义wordpress的实用技巧
  • 企业网站模板源码有哪些报价网站制作
  • 网站建设与网页设计实训报告二级建造师建设云网站
  • 网站后缀gov汕头网站建设小程序
  • 一个空间做多个网站wordpress大改动
  • 桂林北站到机场大巴专线时刻表wordpress 分类 标签
  • 自媒体网站源码模板dede重庆永川网站建设报价
  • 国外酷炫网站网页前端设计流程
  • 子午谷网站建设世界杯网页设计素材
  • 关于网站建设申请报告电商网站建设价位
  • 网站评价系统源码wordpress笔记本主题
  • 大庆市建设大厦网站广告设计海报
  • 惠州建设工程交易网站网络营销专业的职业生涯规划
  • 网站页面架构图阿里云的企业网站建设
  • 做微商网站有专门做网站的公司吗
  • 潍坊网站建设方案托管天津建站网
  • 前端如何做双语网站信誉好的唐山网站建设
  • 创建网站目录应注意电子商务类网站设计
  • 哪个网站专做进口商品的企业网站建设的方案ppt
  • 网站结构如何优化wordpress4.7.10漏洞
  • 官方网站举例流量型网站
  • DW个人网站怎么做长沙民企人才网
  • 电脑做网站教学友情链接交易
  • 为什么选php语言做网站重庆网站优化seo公司
  • 仿站侵权吗字体设计图片
  • 王建设医生个人网站智能网站搭建
  • 博物馆网站做的好的山东企业站点seo
  • 网站做视频怎么赚钱的平面设计公司哪家好
  • 合作建设网站协议php 个人网站 源码
  • 广州外贸营销型网站手机网站如何推广