Python | Leetcode Python题解之第514题自由之路

题目:

题解:

python 复制代码
Test = "godding"
target = "d"

i = 0

left = i
lc = 0
right = i
rc = 0

while Test[left] != target:
    left -= 1
    lc += 1
    if left == -1:
        left = len(Test) - 1

while Test[right] != target:
    right += 1
    rc += 1
    if right == len(Test):
        right = 0


print(left, lc)
print(right, rc)
相关推荐
云姜.6 分钟前
YAML简单使用
python
喵手10 分钟前
Python爬虫实战:手把手教你Python 自动化构建志愿服务岗位结构化数据库!
爬虫·python·自动化·数据采集·爬虫实战·零基础python爬虫教学·志愿服务岗位结构数据库打造
chushiyunen16 分钟前
python numpy包的使用
开发语言·python·numpy
小邓睡不饱耶17 分钟前
Python多线程爬虫实战:爬取论坛帖子及评论
开发语言·爬虫·python
喵手20 分钟前
Python爬虫实战:手把手教你如何采集开源字体仓库目录页(Google Fonts / 其他公开字体目录)!
爬虫·python·自动化·数据采集·爬虫实战·零基础python爬虫教学·开源字体仓库目录页采集
Chase_______36 分钟前
【Python 基础】第2章:流程控制完全指南(if/match/while/for)
python
第一程序员39 分钟前
Python高级特性详解:从基础到进阶
python·github
wzhidev1 小时前
04、Python核心数据类型详解:从一段诡异的调试说起
开发语言·python
wzhidev1 小时前
05、Python流程控制与函数定义:从调试现场到工程实践
linux·网络·python
Thomas.Sir1 小时前
第十一章:深入剖析 Prompt 提示工程
python·prompt