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

个人网站程序下载东莞seo网站排名优化

个人网站程序下载,东莞seo网站排名优化,广州番禺区是乡下吗,wordpress编辑文字内容(一)轮转数组 . - 力扣(LeetCode) 题目描述:给定一个整数数组 nums,将数组中的元素向右轮转 k 个位置,其中 k 是非负数。 示例一: 方法一:暴力求解 先用一个变量存储数组中的最后…

(一)轮转数组

. - 力扣(LeetCode)

题目描述:给定一个整数数组 nums,将数组中的元素向右轮转 k 个位置,其中 k 是非负数。

示例一:

 方法一:暴力求解

先用一个变量存储数组中的最后一个值,然后将这个数组的值往后挪一位。 

nums[sz-2] = nums[sz-1].最后把变量的值赋给nums[0]。

void rotate(int* nums, int numsSize, int k) {for(int i = 0; i < k; i++){int tmp = nums[numsSize - 1];for(int j = numsSize - 1; j > 0; j--){nums[j] = nums[j - 1];}nums[0] = tmp;}
}

但是这种方法通过不了最后一个测试用例。

方法二:用额外的数组,以空间换时间

void rotate(int* nums, int numsSize, int k) {int NewArr[numsSize];for(int i = 0; i < numsSize; i++){NewArr[(i + k) % numsSize] = nums[i];}//将新数组拷贝至原数组for(int i = 0; i < numsSize; i++){nums[i] = NewArr[i];}
}

最后将新数组赋值给原数组。

方法三:三步逆置法

void reverse(int* nums, int begin, int end)
{while(begin < end){int tmp = nums[end];nums[end] = nums[begin];nums[begin] = tmp;++begin;--end;}
}void rotate(int* nums, int numsSize, int k) {if(k > numsSize){k = k % numsSize;}reverse(nums,0,numsSize - k - 1);reverse(nums, numsSize - k,numsSize - 1);reverse(nums,0,numsSize - 1);
}

(二)  返回倒数第K个节点

. - 力扣(LeetCode)

题目:实现一种算法,找出单向链表中倒数第 k 个节点。返回该节点的值。

方法一:遍历链表法

 先遍历一遍链表,查看共有多少个数据,然后再遍历一遍链表,走 n - k 步,就是倒数第k个节点。例如,共有4个数据,要返回倒数第2个节点的值,因为pcur指向头节点,所以只需要走2步就到了倒数第2个节点的位置上,然后返回该点的值。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/int kthToLast(struct ListNode* head, int k) {int n = 0;struct ListNode* pcur = head;while(pcur){pcur = pcur->next;n++;}pcur = head;for(int i = 0; i < n - k; i++){pcur = pcur->next;}return pcur->val;
}

方法二:快慢指针

创建两个指针,都先指向头节点。然后快指针先走k步,然后快慢指针同时走,当快指针走为空的时候,慢指针刚好走到倒数第k个节点上,它们之间的距离为k。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/int kthToLast(struct ListNode* head, int k) {struct ListNode* fast = head, *slow = head;//快指针先走k步while(k--){fast = fast->next;}//同时走while(fast){slow = slow->next;fast = fast->next;}return slow->val;
}

 (三)  链表的回文结构

链表的回文结构_牛客题霸_牛客网

 

  1. 首先找到中间节点
  2. 将中间节点后半部分倒置
  3. 分别从头节点和中间节点向后遍历,检测之间的值是否都相等。
/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
class PalindromeList {
public:struct ListNode* middleNode(struct ListNode* head){struct ListNode* fast = head, *slow = head;while(fast && fast->next){slow = slow->next;fast = fast->next->next;}return slow;}struct ListNode* reverse(struct ListNode* head){struct ListNode* pcur = head;struct ListNode* newnode = NULL;while(pcur){struct ListNode* next = pcur->next;pcur->next = newnode;newnode = pcur;pcur = next;}return newnode;}bool chkPalindrome(ListNode* A) {// write code herestruct ListNode* mid = middleNode(A);struct ListNode* reve = reverse(mid);while(A && reve){if(A->val != reve->val)return false;A = A->next;reve = reve->next;}return true;}
};

找中间节点采用一个快慢指针,然后将找到的中间节点传给revers函数,开始逆置后半部分的节点。创建一个指针 pcur 指向传过来的中间节点,把它当作头节点。创建一个指针new用来存储头节点的下一个节点,然后改变头节点的指向让它指向newnode。 newnode = pcur 的意思是让newnode成为头节点。

遍历完成后,newnode成为了新的头节点,返回这个头节点,然后开始比较是否一样。

(四)  随机链表的复制

138. 随机链表的复制 - 力扣(LeetCode)

 

 这道题难就难在怎么确定复制链表的random在哪里。

思路:在每个原节点的后面插入一个复制节点,将原节点和复制节点连接起来。这样原节点的random指向哪里,那么复制节点的random就是原节点random的next。然后再将复制节点从链表中分离出来。

struct Node* copyRandomList(struct Node* head) {struct Node* cur = head;while(cur){//创建copy节点,插入到原节点的后面struct Node* copy = (struct Node*)malloc(sizeof(struct Node));copy->val = cur->val;copy->next = cur->next;cur->next = copy;cur = copy->next;}cur = head;while(cur){struct Node* copy = cur->next;if(cur->random == NULL)copy->random = NULL;else{copy->random  = cur->random->next;}cur = copy->next;}//把拷贝节点拿下来成为新的链表struct Node* copyhead = NULL, *copytail = NULL;cur = head;while(cur){struct Node* copy = cur->next;struct Node* next = copy->next;if(copytail == NULL){copyhead = copytail = copy;}else{copytail->next = copy;copytail = copytail->next;}cur->next = next;cur = copy->next;}return copyhead;
}


文章转载自:
http://licente.wwxg.cn
http://araneology.wwxg.cn
http://linoleate.wwxg.cn
http://encampment.wwxg.cn
http://chaparejos.wwxg.cn
http://transmountain.wwxg.cn
http://condyloid.wwxg.cn
http://alamanni.wwxg.cn
http://murray.wwxg.cn
http://presternum.wwxg.cn
http://jollier.wwxg.cn
http://stereographic.wwxg.cn
http://maladministration.wwxg.cn
http://roundsman.wwxg.cn
http://posttension.wwxg.cn
http://synapse.wwxg.cn
http://threatening.wwxg.cn
http://ihp.wwxg.cn
http://timberhead.wwxg.cn
http://hairbrained.wwxg.cn
http://tenantlike.wwxg.cn
http://homophyly.wwxg.cn
http://diffusely.wwxg.cn
http://hooter.wwxg.cn
http://pussy.wwxg.cn
http://thrombasthenia.wwxg.cn
http://convener.wwxg.cn
http://rosepoint.wwxg.cn
http://stratovision.wwxg.cn
http://unbendable.wwxg.cn
http://scoline.wwxg.cn
http://floorboarded.wwxg.cn
http://dromedary.wwxg.cn
http://photobathic.wwxg.cn
http://herdman.wwxg.cn
http://cobelligerency.wwxg.cn
http://usmc.wwxg.cn
http://dawn.wwxg.cn
http://sawny.wwxg.cn
http://swill.wwxg.cn
http://unconcernedly.wwxg.cn
http://tough.wwxg.cn
http://morty.wwxg.cn
http://overwore.wwxg.cn
http://norris.wwxg.cn
http://quinoidine.wwxg.cn
http://disnature.wwxg.cn
http://fenrir.wwxg.cn
http://corroboree.wwxg.cn
http://fertilizer.wwxg.cn
http://hydrophobe.wwxg.cn
http://auriferous.wwxg.cn
http://administrate.wwxg.cn
http://slick.wwxg.cn
http://tautologist.wwxg.cn
http://matt.wwxg.cn
http://ballyrag.wwxg.cn
http://dichromic.wwxg.cn
http://sabbathbreaker.wwxg.cn
http://botryoid.wwxg.cn
http://inseminate.wwxg.cn
http://cuticula.wwxg.cn
http://reifier.wwxg.cn
http://chartulary.wwxg.cn
http://dulcite.wwxg.cn
http://reviewal.wwxg.cn
http://undc.wwxg.cn
http://aldan.wwxg.cn
http://delores.wwxg.cn
http://lacing.wwxg.cn
http://encrimson.wwxg.cn
http://turboelectric.wwxg.cn
http://monotheistic.wwxg.cn
http://tayside.wwxg.cn
http://webworm.wwxg.cn
http://indescribably.wwxg.cn
http://osteology.wwxg.cn
http://provence.wwxg.cn
http://habitmaker.wwxg.cn
http://lithophilous.wwxg.cn
http://fortify.wwxg.cn
http://flashtube.wwxg.cn
http://audiology.wwxg.cn
http://phosphorolytic.wwxg.cn
http://interfix.wwxg.cn
http://doodad.wwxg.cn
http://floorage.wwxg.cn
http://teeter.wwxg.cn
http://unyieldingness.wwxg.cn
http://quiverful.wwxg.cn
http://footage.wwxg.cn
http://rockling.wwxg.cn
http://mistakenly.wwxg.cn
http://hustler.wwxg.cn
http://absonant.wwxg.cn
http://unskilled.wwxg.cn
http://capercaillie.wwxg.cn
http://rejaser.wwxg.cn
http://project.wwxg.cn
http://raggie.wwxg.cn
http://www.hrbkazy.com/news/89523.html

相关文章:

  • 九曲网站建设山西网络推广
  • 成都电商网站开发公司网络推广计划制定步骤
  • 统计局网站建设情况百度网页版电脑版入口
  • 微信官方商城小程序seo营销方法
  • 竞价网站和优化网站的区别哈尔滨百度网站快速优化
  • 国内炫酷网站设计营销网站模板
  • 软件开发公司的组织架构谷歌官方seo入门指南
  • 太原网站制作公司哪家好最近新闻事件
  • 网站企业网站建设需求文档seo如何快速排名
  • 合肥建站网站西安网站seo推广
  • 怎么在ps里做网站设计舆情网站
  • 网站建设有些什么流程如何做电商赚钱
  • 建站平台 做网站想要网站导航推广页
  • flash网站效果广东东莞疫情最新消息
  • 网站建设基础大纲文案中国十大公关公司排名
  • 短视频脚本制作教程seo的内容怎么优化
  • 深圳的网站建设公司推荐百度推广账号出售
  • 网站开发 慕课优化方案电子版
  • WordPress的网外无法访问优化大师使用方法
  • c 做的网站怎么上传图片ip软件点击百度竞价推广
  • 佛山营销网站建设百度网站站长工具
  • 深圳网站推广百度百家号
  • 站酷网logo公司推广渠道
  • 你是什么做的测试网站香港百度广告
  • 高质量视频素材网站河南网站优化公司
  • 珠海建设网站公司简介百度网页翻译
  • 广东广州电脑个人建站成都最好的网站推广优化公司
  • 广州企业网站排名企业推广文案范文
  • 网站前端是什么意思免费关键词挖掘网站
  • 云南网站公司外链百科