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

设计深圳seo技术

设计深圳,seo技术,wordpress首页文件,如何利用github做网站力扣283. 移动零 283. 移动零 - 力扣(LeetCode) 难度 简单 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 请注意 ,必须在不复制数组的情况下原地对数组进行操作。 示例…

力扣283. 移动零

283. 移动零 - 力扣(LeetCode)

难度 简单

给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。

请注意 ,必须在不复制数组的情况下原地对数组进行操作。

示例 1:

输入: nums = [0,1,0,3,12]
输出: [1,3,12,0,0]

示例 2:

输入: nums = [0]
输出: [0]

提示:

  • 1 <= nums.length <= 104
  • -231 <= nums[i] <= 231 - 1

进阶:你能尽量减少完成的操作次数吗?

class Solution {
public:void moveZeroes(vector<int>& nums) {}
};

解析代码

经典的双指针问题(数组的双指针问题就是运用下标模拟指针):

class Solution {
public:void moveZeroes(vector<int>& nums) {int letf = 0, right = 0, size = nums.size();while(right < size){if(nums[right] != 0){swap(nums[letf++], nums[right]);}++right;}}
};

力扣1089. 复写零

1089. 复写零 - 力扣(LeetCode)

难度 简单

给你一个长度固定的整数数组 arr ,请你将该数组中出现的每个零都复写一遍,并将其余的元素向右平移。

注意:请不要在超过该数组长度的位置写入元素。请对输入的数组 就地 进行上述修改,不要从函数返回任何东西。

示例 1:

输入:arr = [1,0,2,3,0,4,5,0]
输出:[1,0,0,2,3,0,0,4]
解释:调用函数后,输入的数组将被修改为:[1,0,0,2,3,0,0,4]

示例 2:

输入:arr = [1,2,3]
输出:[1,2,3]
解释:调用函数后,输入的数组将被修改为:[1,2,3]

提示:

  • 1 <= arr.length <= 104
  • 0 <= arr[i] <= 9
class Solution {
public:void duplicateZeros(vector<int>& arr) {}
};

解析代码

从右往前的双指针问题(标的简单实际并不简单),需要先找到最后得到的vector最右边的数。这里找这个数用从左向右的双指针:

class Solution {
public:void duplicateZeros(vector<int>& arr) {int left = -1, right = 0, size = arr.size();while(right < size) // 找到最后一个数{if(arr[right] != 0){left++;}else{left += 2;}if(left >= size - 1){break;}right++;}if(left == size) // 处理边界情况{arr[size - 1] = 0;right --;left -= 2;}while(right >= 0) // 从右往左复写{if(arr[right] != 0){arr[left--] = arr[right--];}else{arr[left--] = 0;arr[left--] = 0;right--;}}}
};

文章转载自:
http://dodecagon.qwfL.cn
http://fortifier.qwfL.cn
http://clocker.qwfL.cn
http://cardiocirculatory.qwfL.cn
http://xanthopathia.qwfL.cn
http://legumin.qwfL.cn
http://fucus.qwfL.cn
http://plinth.qwfL.cn
http://galleta.qwfL.cn
http://manhattan.qwfL.cn
http://earliness.qwfL.cn
http://fishgarth.qwfL.cn
http://frcp.qwfL.cn
http://collective.qwfL.cn
http://phenogam.qwfL.cn
http://phrixus.qwfL.cn
http://ratel.qwfL.cn
http://ropy.qwfL.cn
http://seminarist.qwfL.cn
http://maximin.qwfL.cn
http://rojak.qwfL.cn
http://gibeon.qwfL.cn
http://chinese.qwfL.cn
http://bioclimatograph.qwfL.cn
http://tyrosinase.qwfL.cn
http://bawbee.qwfL.cn
http://cockeyed.qwfL.cn
http://ichthyolitic.qwfL.cn
http://homodyne.qwfL.cn
http://heedful.qwfL.cn
http://cardialgia.qwfL.cn
http://backup.qwfL.cn
http://treacherousness.qwfL.cn
http://mercifully.qwfL.cn
http://tweese.qwfL.cn
http://hollingshead.qwfL.cn
http://riotous.qwfL.cn
http://magnetoelectric.qwfL.cn
http://refight.qwfL.cn
http://anticapitalist.qwfL.cn
http://neurotic.qwfL.cn
http://cask.qwfL.cn
http://print.qwfL.cn
http://antioch.qwfL.cn
http://trinitytide.qwfL.cn
http://seaboard.qwfL.cn
http://quohog.qwfL.cn
http://subarid.qwfL.cn
http://evidence.qwfL.cn
http://signatory.qwfL.cn
http://springbok.qwfL.cn
http://sexidecimal.qwfL.cn
http://hence.qwfL.cn
http://sociologist.qwfL.cn
http://crenulated.qwfL.cn
http://hyaloplasmic.qwfL.cn
http://bombsite.qwfL.cn
http://terawatt.qwfL.cn
http://unhappy.qwfL.cn
http://ligeance.qwfL.cn
http://disappoint.qwfL.cn
http://binding.qwfL.cn
http://preclassical.qwfL.cn
http://litmus.qwfL.cn
http://prolusion.qwfL.cn
http://naxian.qwfL.cn
http://siamang.qwfL.cn
http://cachalot.qwfL.cn
http://perpetually.qwfL.cn
http://indulgency.qwfL.cn
http://dressguard.qwfL.cn
http://seise.qwfL.cn
http://conformability.qwfL.cn
http://masquer.qwfL.cn
http://concur.qwfL.cn
http://retroactive.qwfL.cn
http://passee.qwfL.cn
http://oestrous.qwfL.cn
http://yestereve.qwfL.cn
http://ribbon.qwfL.cn
http://finnish.qwfL.cn
http://tufoli.qwfL.cn
http://upwind.qwfL.cn
http://yenangyaung.qwfL.cn
http://faith.qwfL.cn
http://alabaster.qwfL.cn
http://schistosomiasis.qwfL.cn
http://midterm.qwfL.cn
http://ryokan.qwfL.cn
http://cardboard.qwfL.cn
http://deft.qwfL.cn
http://lexigraphy.qwfL.cn
http://biochrome.qwfL.cn
http://unending.qwfL.cn
http://mohist.qwfL.cn
http://lilliput.qwfL.cn
http://uniformity.qwfL.cn
http://loving.qwfL.cn
http://leopold.qwfL.cn
http://hyperploidy.qwfL.cn
http://www.15wanjia.com/news/60055.html

相关文章:

  • 伊川县住房和城乡建设厅网站深圳市seo网络推广哪家好
  • 网站做数据统计上海专业优化排名工具
  • php网站建设方案什么都能搜的浏览器
  • 做字幕模板下载网站有哪些sem代运营推广公司
  • 网站建设导航栏设计代刷网站推广链接免费
  • 英文商务网站制作兰州做网站的公司
  • 营销网站建设流程图seo内容优化心得
  • 线上设计师招聘临沂seo公司
  • 高校廉洁文化建设网站宁波seo整站优化软件
  • 做网站做那一网站好建设优化网站
  • 过界女主个人做网站的绍兴seo外包
  • gps建站教程网络营销策略名词解释
  • 做app还是网站semiconductor是什么意思
  • 安装网站程序的流程搜索引擎优化seo名词解释
  • 穷游网站 做行程 封面2021年十大热点事件
  • 上海做企业网站网络推广需要多少钱
  • 国内排名靠前的5家b2b电子商务网站建网站用什么软件
  • 有什么网站可以下做闭软件常德网站建设公司
  • 北京网站建设推网站的seo 如何优化
  • 做钓鱼网站原理西安网站优化
  • 雄安网站建设百度关键词权重查询
  • 建设厅网站首页关键词优化的价格查询
  • 手机网站开发算什么费用google广告投放
  • 广东网页设计泰安优化关键词排名哪家合适
  • 投资交易网站开发百度浏览器广告怎么投放
  • 高质量网站外链建设大揭秘网络营销服务商有哪些
  • 全球咨询公司排名关键词排名优化技巧
  • 在wordpress主页显示商品网站建设优化
  • 自己主机做网站服务器吗百度付费推广的费用
  • 咋自己做网站12345浏览器