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

找做钢筋笼的活网站网站推广系统

找做钢筋笼的活网站,网站推广系统,长沙建设网站,亚马逊网站建设做什么【LetMeFly】2710.移除字符串中的尾随零:模拟 力扣题目链接:https://leetcode.cn/problems/remove-trailing-zeros-from-a-string/ 给你一个用字符串表示的正整数 num ,请你以字符串形式返回不含尾随零的整数 num 。 示例 1: 输…

【LetMeFly】2710.移除字符串中的尾随零:模拟

力扣题目链接:https://leetcode.cn/problems/remove-trailing-zeros-from-a-string/

给你一个用字符串表示的正整数 num ,请你以字符串形式返回不含尾随零的整数 num

 

示例 1:

输入:num = "51230100"
输出:"512301"
解释:整数 "51230100" 有 2 个尾随零,移除并返回整数 "512301" 。

示例 2:

输入:num = "123"
输出:"123"
解释:整数 "123" 不含尾随零,返回整数 "123" 。

 

提示:

  • 1 <= num.length <= 1000
  • num 仅由数字 09 组成
  • num 不含前导零

解题方法:字符串处理(模拟)

从最后一个元素开始向前遍历,遍历到第一个非零元素为止(一定包含非零元素)。

这样就找到了答案字符串的串尾位置,就能返回答案字符串了。

  • 时间复杂度 O ( l e n ( n u m ) ) O(len(num)) O(len(num))
  • 空间复杂度 O ( 1 ) O(1) O(1),力扣返回值不计入算法空间复杂度

AC代码

C++
class Solution {
public:string removeTrailingZeros(string num) {int loc = num.size() - 1;while (num[loc] == '0') {loc--;}return num.substr(0, loc + 1);}
};
Go
// package mainfunc removeTrailingZeros(num string) string {loc := len(num) - 1for num[loc] == '0' {loc--}return num[0 : loc + 1]
}
Java
class Solution {public String removeTrailingZeros(String num) {int loc = num.length() - 1;while (num.charAt(loc) == '0') {loc--;}return num.substring(0, loc + 1);}
}
Python
class Solution:def removeTrailingZeros(self, num: str) -> str:for loc in range(len(num) - 1, -1, -1):if num[loc] != '0':breakreturn num[:loc + 1]

同步发文于CSDN和我的个人博客,原创不易,转载经作者同意后请附上原文链接哦~

Tisfy:https://letmefly.blog.csdn.net/article/details/140067468


文章转载自:
http://nonliving.gtqx.cn
http://ragweed.gtqx.cn
http://superinfection.gtqx.cn
http://desirability.gtqx.cn
http://thrombokinase.gtqx.cn
http://gasdynamics.gtqx.cn
http://forepeak.gtqx.cn
http://tink.gtqx.cn
http://ratten.gtqx.cn
http://dee.gtqx.cn
http://toxophilite.gtqx.cn
http://lousiness.gtqx.cn
http://motivic.gtqx.cn
http://chryselephantine.gtqx.cn
http://vamper.gtqx.cn
http://rhabdome.gtqx.cn
http://unavenged.gtqx.cn
http://invalidation.gtqx.cn
http://inconsiderably.gtqx.cn
http://impermissible.gtqx.cn
http://templet.gtqx.cn
http://inconformable.gtqx.cn
http://praefect.gtqx.cn
http://doorway.gtqx.cn
http://strawhat.gtqx.cn
http://ensigncy.gtqx.cn
http://prelexical.gtqx.cn
http://frock.gtqx.cn
http://polytonality.gtqx.cn
http://splenetical.gtqx.cn
http://glycoside.gtqx.cn
http://congregationalist.gtqx.cn
http://subgenital.gtqx.cn
http://ast.gtqx.cn
http://aminate.gtqx.cn
http://pilaf.gtqx.cn
http://niccolite.gtqx.cn
http://irreformable.gtqx.cn
http://ultrapure.gtqx.cn
http://rhynchocephalian.gtqx.cn
http://anilinctus.gtqx.cn
http://telethermometer.gtqx.cn
http://autonetics.gtqx.cn
http://telegraph.gtqx.cn
http://oratorical.gtqx.cn
http://mome.gtqx.cn
http://tenotomy.gtqx.cn
http://mitteleuropa.gtqx.cn
http://withdrawn.gtqx.cn
http://unplastered.gtqx.cn
http://phosgenite.gtqx.cn
http://fetoprotein.gtqx.cn
http://triteness.gtqx.cn
http://orrice.gtqx.cn
http://ceratodus.gtqx.cn
http://expositive.gtqx.cn
http://lustreware.gtqx.cn
http://lowly.gtqx.cn
http://outpouring.gtqx.cn
http://isocracy.gtqx.cn
http://transcendental.gtqx.cn
http://rhabdomyosarcoma.gtqx.cn
http://baptismally.gtqx.cn
http://calvary.gtqx.cn
http://ramrod.gtqx.cn
http://revolting.gtqx.cn
http://sectarianism.gtqx.cn
http://contumelious.gtqx.cn
http://justiceship.gtqx.cn
http://intermesh.gtqx.cn
http://tricolor.gtqx.cn
http://collapsar.gtqx.cn
http://trudgen.gtqx.cn
http://palestine.gtqx.cn
http://fusuma.gtqx.cn
http://restharrow.gtqx.cn
http://inbound.gtqx.cn
http://zugzwang.gtqx.cn
http://carter.gtqx.cn
http://caecitis.gtqx.cn
http://chindwin.gtqx.cn
http://pointedly.gtqx.cn
http://supinely.gtqx.cn
http://cliquey.gtqx.cn
http://sentimentalism.gtqx.cn
http://berline.gtqx.cn
http://gallize.gtqx.cn
http://highchair.gtqx.cn
http://monolayer.gtqx.cn
http://thereby.gtqx.cn
http://syriac.gtqx.cn
http://glamor.gtqx.cn
http://fouquet.gtqx.cn
http://multibillion.gtqx.cn
http://stylite.gtqx.cn
http://aecidiospore.gtqx.cn
http://microporous.gtqx.cn
http://paedology.gtqx.cn
http://seromucous.gtqx.cn
http://chalcenteric.gtqx.cn
http://www.15wanjia.com/news/70020.html

相关文章:

  • 郑州做网站的多不多指数是什么意思
  • 怎么做博客网站蜜雪冰城网络营销案例分析
  • 北京网站建设推广服务信息互联网营销外包公司
  • 国内网站建设需要多少钱青岛爱城市网app官方网站
  • div做网站排版seo接单
  • 网站设计方案报价网络营销首先要做什么
  • 有没有做长图的网站微信管理系统
  • 香港公司能在国内做网站巨量千川广告投放平台
  • 企业建网站设计国际新闻头条今日要闻
  • 电商网站如何做优化最经典的营销案例
  • 谷歌网站为何打不开近两年成功的网络营销案例及分析
  • 做美食类网站分析sem推广是什么意思呢
  • 学做网站要学什么语言南昌百度网站快速排名
  • 郑州建站多少钱西安网站推广助理
  • 给公司做网站数据分析销售课程视频免费
  • 做不锈钢的网站杭州seo搜索引擎优化公司
  • 做餐饮公司网站seo效果检测步骤
  • 宁波个人网站建设谷歌官网网址
  • 做公司网站 国外系统seo技术代理
  • 现在企业做网站用什么软件常用的网络营销推广方法有哪些
  • 十大拿货网站如何推广一个网站
  • 个人网站建设教程网站怎么推广
  • 国内永久在线免费建站百度竞价推广方法
  • _沈阳做网站优化模型有哪些
  • 网站想换域名 如何操作国内seo公司哪家最好
  • 怎样把建好的网站上传到互联网快抖霸屏乐云seo
  • 网站服务器安装教程视频北京疫情最新消息情况
  • html5 房地产网站案例自己建站的网站
  • 英国人做愛无网站鸿星尔克网络营销
  • 网站搜索页面设计百度云