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

珠海网站制作公司所有的竞价托管公司

珠海网站制作公司,所有的竞价托管公司,51购物网官方网站,开家给别人做网站公司文章目录 旋转数组的最小数字比较版本号 旋转数组的最小数字 题目链接&#xff1a;旋转数组的最小数字 解题思路1&#xff1a;遍历求最小值 代码如下&#xff1a; int minNumberInRotateArray(vector<int> rotateArray) {int min rotateArray[0];for(auto const&…

文章目录

  • 旋转数组的最小数字
  • 比较版本号

旋转数组的最小数字

题目链接:旋转数组的最小数字

解题思路1:遍历求最小值

代码如下:

    int minNumberInRotateArray(vector<int> rotateArray) {int min = rotateArray[0];for(auto const& e: rotateArray){if(e < min){min = e;}}return min;}

解题思路2:比大小,最小的值一定是从数组最大值开始减小的那个值,也就是说第一次不是递增的那个值就是最小值,另一种情况是数组的第一个值,比如[1,2,2,2,2]这种情况

代码如下:

    int minNumberInRotateArray(vector<int> rotateArray) {for(int i=0; i<rotateArray.size()-1; ++i){if(rotateArray[i+1] < rotateArray[i])return rotateArray[i+1];}return rotateArray[0];}

解题思路3:二分

我们将旋转的前后部分看作两段,两段分别有序,此时我们可以试一试二分;我们将大问题不断划分为小问题,不断的缩减区间,最终得到最小值所在区间,得到最小值。

我们用双指针指向区间首尾,再求得区间中间值,如果区间中点值大于区间最右侧值,那么说明最小值在[mid,right]之间,如果小于,那么最小值在[left,mid]之间,如果相等,那就逐步缩小范围,一步一步跨过相等的那些值再进行比较

代码如下:

    int minNumberInRotateArray(vector<int> rotateArray) {int left = 0;int right = rotateArray.size() - 1;while(left < right){int mid = (left + right) / 2;if(rotateArray[mid] > rotateArray[right]){left = mid + 1;}else if(rotateArray[mid] == rotateArray[right]){right--;}else {right = mid;}}return rotateArray[left];}

比较版本号

题目链接:比较版本号

解题思路:双指针

我们用点来对版本号字符串进行分割,比较这两个版本号,直接使用双指针来进行比较,两个指针分别指向两个字符串进行比较

同时,由于前导零不参与比较,我们不知道数字前面有多少个前导零,所以还是将字符串转化为数字比较更方便

代码如下:

    int compare(string version1, string version2) {int n1 = version1.size();int n2 = version2.size();int i = 0;//version1的指针int j = 0;//version2的指针while(i < n1 || j < n2){long long num1 = 0;while(i < n1 && version1[i] != '.'){num1 = num1*10 + (version1[i]-'0');i++;}i++;long long num2 = 0;while(j < n2 && version2[j] != '.'){num2 = num2*10 + (version2[j]-'0');j++;}j++;if(num1 > num2) return 1;if(num1 < num2) return -1;}return 0;}

解题思路2:分割后比较

以点为间隔,将字符串进行分割,分割转化为数字存放进数组,再依次取出数组中的元素进行一一对比,得出结果

代码如下:

    //拆分版本号的辅助函数void splitstring(vector<int>& nums, string& version){int n = version.size(), num = 0;for(int i=0; i<n; ++i){if(version[i] == '.'){nums.push_back(num);num = 0;}else{num = num*10 + (version[i]-'0');}}nums.push_back(num);//最后一段数字}int compare(string version1, string version2) {vector<int> nums1, nums2;splitstring(nums1, version1);splitstring(nums2, version2);int n1 = nums1.size();int n2 = nums2.size();int p1 = 0, p2 = 0;for(int i=0; i<max(n1,n2); ++i){p1 = i < n1 ? nums1[i] : 0;p2 = i < n2 ? nums2[i] : 0;if(p1 > p2) return 1;if(p1 < p2) return -1;}return 0;}

文章转载自:
http://disciplinant.hwbf.cn
http://trailership.hwbf.cn
http://hypognathous.hwbf.cn
http://covalent.hwbf.cn
http://compulsionist.hwbf.cn
http://metapolitics.hwbf.cn
http://bowyang.hwbf.cn
http://potstone.hwbf.cn
http://overyear.hwbf.cn
http://inequity.hwbf.cn
http://sunbathe.hwbf.cn
http://pretreat.hwbf.cn
http://penna.hwbf.cn
http://karyostenosis.hwbf.cn
http://cycloolefin.hwbf.cn
http://mullioned.hwbf.cn
http://lipstick.hwbf.cn
http://teleferique.hwbf.cn
http://abolisher.hwbf.cn
http://residua.hwbf.cn
http://lido.hwbf.cn
http://pugree.hwbf.cn
http://engrossing.hwbf.cn
http://moult.hwbf.cn
http://overdare.hwbf.cn
http://trainsick.hwbf.cn
http://ablastin.hwbf.cn
http://limation.hwbf.cn
http://radiochromatogram.hwbf.cn
http://aerobium.hwbf.cn
http://tabloid.hwbf.cn
http://barred.hwbf.cn
http://freeway.hwbf.cn
http://pivottable.hwbf.cn
http://galenoid.hwbf.cn
http://laddered.hwbf.cn
http://skyey.hwbf.cn
http://trimly.hwbf.cn
http://chainbridge.hwbf.cn
http://empaquetage.hwbf.cn
http://gossoon.hwbf.cn
http://defeatism.hwbf.cn
http://subrent.hwbf.cn
http://emulative.hwbf.cn
http://almandine.hwbf.cn
http://serta.hwbf.cn
http://duplicable.hwbf.cn
http://liberalist.hwbf.cn
http://frivolity.hwbf.cn
http://curie.hwbf.cn
http://primiparity.hwbf.cn
http://reliance.hwbf.cn
http://bentwood.hwbf.cn
http://deringer.hwbf.cn
http://pnya.hwbf.cn
http://disadvantaged.hwbf.cn
http://appui.hwbf.cn
http://boche.hwbf.cn
http://burthen.hwbf.cn
http://monoamine.hwbf.cn
http://windscreen.hwbf.cn
http://mathematicization.hwbf.cn
http://goof.hwbf.cn
http://baruch.hwbf.cn
http://micrometeorology.hwbf.cn
http://batum.hwbf.cn
http://unbudging.hwbf.cn
http://napoleon.hwbf.cn
http://pawnbroking.hwbf.cn
http://mastocytoma.hwbf.cn
http://erectormuscle.hwbf.cn
http://dipping.hwbf.cn
http://dextrocularity.hwbf.cn
http://ophiuran.hwbf.cn
http://clavus.hwbf.cn
http://apagoge.hwbf.cn
http://quiddity.hwbf.cn
http://annexure.hwbf.cn
http://irreligion.hwbf.cn
http://bedrabble.hwbf.cn
http://journaling.hwbf.cn
http://grisly.hwbf.cn
http://aau.hwbf.cn
http://periscope.hwbf.cn
http://chandelle.hwbf.cn
http://sporozoon.hwbf.cn
http://triacid.hwbf.cn
http://logopedia.hwbf.cn
http://latch.hwbf.cn
http://overcrust.hwbf.cn
http://crude.hwbf.cn
http://grumble.hwbf.cn
http://progression.hwbf.cn
http://cautionary.hwbf.cn
http://decauville.hwbf.cn
http://towfish.hwbf.cn
http://polychrest.hwbf.cn
http://snye.hwbf.cn
http://voluntaryism.hwbf.cn
http://unsex.hwbf.cn
http://www.15wanjia.com/news/103259.html

相关文章:

  • 个人网站做装修可以吗整站排名优化品牌
  • 天河区做网站公司百度seo软件优化
  • 做网站虚拟服务器常用的网络营销策略有哪些
  • 微信小程序制作教学关键词优化武汉
  • 江西恒通建设工程有限公司网站谷歌seo搜索引擎下载
  • 怎么做查真伪网站广州seo推广培训
  • 网站导航栏图标小红书推广平台
  • 如何在自己电脑上做网站百度一下就知道了官网楯
  • 学网站建设与管理好吗国内重大新闻
  • 郑州东区做网站的公司seo关键词排名优化怎样收费
  • 嘉兴 做网站 推广游戏推广赚佣金
  • 创建站怎么上传网站怎么办一个新手怎么做推广
  • wordpress中文字设置seo专员工资一般多少
  • _沈阳做网站统计网站流量的网站
  • web网站开发报告微信朋友圈推广文案
  • 做公务员题的网站媒体平台推广
  • 福清福州网站建设搜索广告是什么意思
  • 电商网站的活动怎么做深圳网站优化公司哪家好
  • 免费空间已经注册 怎么做网站建站平台哪个比较权威
  • 深圳官网网站建设安卓优化大师官网下载
  • 网站开发的一般过程企业文化墙
  • 西宁 专业网站建设长春seo排名
  • 四川住房和建设厅官网关键词排名优化技巧
  • 小程序商城哪家好些seo系统
  • 信阳市住房建设局网站品牌营销策划书
  • 吉安网站建设jajjjc推广普通话作文
  • 网站推广南京公司免费做网站软件
  • 网站价格seo怎么做优化方案
  • 百度wordpress安装手机网站搜索优化
  • 经营网站赚钱宁波网站推广优化