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)
相关推荐
wuhuhuan7 分钟前
Case Generator 平台升级
python·测试工具·自动化
RobinDevNotes10 分钟前
用 Profile 揪出大模型训练性能瓶颈
python·性能优化
李航198317 分钟前
用 DeepDraw 几何引擎开发建筑设计软件(六):创建画线工具
python·软件构建
AI 编程助手GPT17 分钟前
Python 备份 SQLite:为什么复制了 .db,恢复后还是少数据?
人工智能·python·ai·chatgpt
狗都不学爬虫_31 分钟前
AI逆向 - 天御无感点击验证(补+纯)
爬虫·python·网络爬虫
529宝宝起名网1 小时前
用 Python 开发历史名字查询与起名灵感工具:从古籍人物数据库到名字文化故事生成
开发语言·前端·python
用户298698530141 小时前
Python 将 HTML 转换为 Word 文档的实践指南
python·html·api
维克兜率天1 小时前
【维克】模块3总结:从一行空数据,到一个能跑的模型
python·深度学习·算法
飞Link1 小时前
定积分理论与 Python 仿真完全指南
python·算法
小静AI工程实验室2 小时前
Python 爬虫翻页为何重复、漏数据?SQLite 复现 OFFSET、复合游标与快照的 8 项检查
爬虫·python·sqlite