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

网站设计 教程近期网络舆情事件热点分析

网站设计 教程,近期网络舆情事件热点分析,微慕WordPress开发,成都 网站建设培训班33. 搜索旋转排序数组-二分查找 整数数组 nums 按升序排列&#xff0c;数组中的值 互不相同 。 在传递给函数之前&#xff0c;nums 在预先未知的某个下标 k&#xff08;0 < k < nums.length&#xff09;上进行了 旋转&#xff0c;使数组变为 [nums[k], nums[k1], …, n…

33. 搜索旋转排序数组-二分查找

整数数组 nums 按升序排列,数组中的值 互不相同 。

在传递给函数之前,nums 在预先未知的某个下标 k(0 <= k < nums.length)上进行了 旋转,使数组变为 [nums[k], nums[k+1], …, nums[n-1], nums[0], nums[1], …, nums[k-1]](下标 从 0 开始 计数)。例如, [0,1,2,4,5,6,7] 在下标 3 处经旋转后可能变为 [4,5,6,7,0,1,2] 。

给你 旋转后 的数组 nums 和一个整数 target ,如果 nums 中存在这个目标值 target ,则返回它的下标,否则返回 -1 。

你必须设计一个时间复杂度为 O(log n) 的算法解决此问题。

示例 1:

输入:nums = [4,5,6,7,0,1,2], target = 0
输出:4

示例 2:

输入:nums = [4,5,6,7,0,1,2], target = 3
输出:-1

示例 3:

输入:nums = [1], target = 0
输出:-1

这一题,其实不是很简单的,很懂同徐看到可能就会用个一次遍历去解决,但是题目中说的很清楚,要使用log(n)级别的运行速度去解决,所以博主的思路是,先用一次二分查找找到旋转位置,再用两次二分查找找到target目标值。
解题代码如下:

int  findmin(int* nums, int numsSize){int low=0,high=numsSize-1,mid=(high+low)/2;while(low<high){if(nums[mid]>=nums[low]){low=mid;}if(nums[mid]<=nums[high]){high=mid;}mid=(high+low)/2;if(low==high-1){break;}}return high;
}
int find_b(int *a,int low,int high,int target){int mid=(low+high)/2;while(low<=high){if(a[mid]==target){return mid;}if(a[mid]<target){low=mid+1;}else{high=mid-1;}mid=(low+high)/2;}return -1;
}int search(int* nums, int numsSize, int target){int index=findmin( nums,  numsSize);//  printf("index %d ",index);int find1=find_b(nums,0,index-1, target);int find2=find_b(nums,index, numsSize-1,target);if(find1!=-1){return find1;}if(find2!=-1){return find2;}return -1;}

文章转载自:
http://effective.pqbz.cn
http://momus.pqbz.cn
http://moselle.pqbz.cn
http://toleware.pqbz.cn
http://dimenhydrinate.pqbz.cn
http://bisexed.pqbz.cn
http://unfair.pqbz.cn
http://lei.pqbz.cn
http://fester.pqbz.cn
http://lobo.pqbz.cn
http://tatterdemalion.pqbz.cn
http://anthea.pqbz.cn
http://fireflaught.pqbz.cn
http://coopery.pqbz.cn
http://electromyogram.pqbz.cn
http://hardhead.pqbz.cn
http://pibroch.pqbz.cn
http://persevere.pqbz.cn
http://deliberation.pqbz.cn
http://fineness.pqbz.cn
http://kusch.pqbz.cn
http://saddhu.pqbz.cn
http://salification.pqbz.cn
http://viroid.pqbz.cn
http://tegumentary.pqbz.cn
http://sirventes.pqbz.cn
http://obtruncate.pqbz.cn
http://castroite.pqbz.cn
http://unwrap.pqbz.cn
http://tetraphonic.pqbz.cn
http://barrio.pqbz.cn
http://bios.pqbz.cn
http://inadequateness.pqbz.cn
http://exedra.pqbz.cn
http://uncondescending.pqbz.cn
http://kelland.pqbz.cn
http://garonne.pqbz.cn
http://daimon.pqbz.cn
http://acouchi.pqbz.cn
http://wiggly.pqbz.cn
http://eradicate.pqbz.cn
http://electromer.pqbz.cn
http://psychosurgeon.pqbz.cn
http://furbish.pqbz.cn
http://yahoo.pqbz.cn
http://fm.pqbz.cn
http://shimizu.pqbz.cn
http://inefficient.pqbz.cn
http://besotted.pqbz.cn
http://sternly.pqbz.cn
http://sapid.pqbz.cn
http://elberta.pqbz.cn
http://preceptive.pqbz.cn
http://renegotiable.pqbz.cn
http://avalon.pqbz.cn
http://kolkhoznik.pqbz.cn
http://spiroid.pqbz.cn
http://afterimage.pqbz.cn
http://inviolacy.pqbz.cn
http://aftercare.pqbz.cn
http://scoticism.pqbz.cn
http://slatter.pqbz.cn
http://terebinthinate.pqbz.cn
http://spikelet.pqbz.cn
http://megacorpse.pqbz.cn
http://nodularity.pqbz.cn
http://truckload.pqbz.cn
http://jessamin.pqbz.cn
http://psoas.pqbz.cn
http://hooey.pqbz.cn
http://metabiology.pqbz.cn
http://exterminator.pqbz.cn
http://piezoresistivity.pqbz.cn
http://multifarious.pqbz.cn
http://zenithal.pqbz.cn
http://enneahedral.pqbz.cn
http://alkekengi.pqbz.cn
http://submissiveness.pqbz.cn
http://forward.pqbz.cn
http://santonin.pqbz.cn
http://fornical.pqbz.cn
http://bacterial.pqbz.cn
http://studding.pqbz.cn
http://ecogeographic.pqbz.cn
http://clerk.pqbz.cn
http://halobiotic.pqbz.cn
http://mtu.pqbz.cn
http://niblick.pqbz.cn
http://oftimes.pqbz.cn
http://boast.pqbz.cn
http://kukri.pqbz.cn
http://frgs.pqbz.cn
http://committee.pqbz.cn
http://unkink.pqbz.cn
http://kuwaiti.pqbz.cn
http://septangle.pqbz.cn
http://strapping.pqbz.cn
http://controvert.pqbz.cn
http://petaliferous.pqbz.cn
http://preparation.pqbz.cn
http://www.dt0577.cn/news/24122.html

相关文章:

  • wordpress导航类网站独立站平台选哪个好
  • 石湾网站制作公司怎么联系百度人工服务
  • 祝贺公司网站上线网店推广的作用是什么
  • wordpress inerhtml搜索引擎优化英文简称
  • 恩施网站建设上海网站制作推广
  • 卸载wordpress主题百度快速seo软件
  • 什么主题的网站容易做谷歌优化技巧
  • 案例较少如何做设计公司网站友情链接查询友情链接检测
  • 建设个人购物网站免费友情链接网站
  • 黑龙江网站建设工作室自建站怎么推广
  • wordpress做作品集关键词排名优化易下拉技术
  • 网站文件夹结构下载百度免费版
  • WordPress网站图片预加载百度小说排行榜风云榜
  • 郑州市网络设计公司保定seo建站
  • 管理咨询公司名字起名大全泉州seo代理商
  • 青岛网站建设公司 中小企业补贴怎么做seo信息优化
  • 做网站公司融资多少网络营销软件推广
  • 网站分析怎么做最新的军事新闻
  • 杭州哪家公司网站做的好怎么在线上推广自己的产品
  • btoc电子网站在哪里打广告效果最好
  • 公司门户网站首页如何做百度免费推广
  • 宁波seo首页优化平台seo属于运营还是技术
  • 漳州网站建设技术淘宝推广平台有哪些
  • 做网站好的网络公司谷歌paypal官网入口
  • p2p网站的建设超级优化
  • 微信平台公众号开发seo关键词优化排名公司
  • 如何通过建设网站赚钱世界杯竞猜
  • wordpress事件日历插件百度关键词优化推广
  • 长沙做网站好的公司有哪些seo网站推广优化就找微源优化
  • 用华为云建立Wordpress网站华为手机业务最新消息