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)
相关推荐
xlrqx3 小时前
家电清洗培训课程类别、培训方式及费用情况究竟有哪些
大数据·python
lbb 小魔仙4 小时前
VS Code Python 高级调试技巧:从入门到精通
开发语言·python
lzqrzpt4 小时前
LED驱动电源行业品牌格局与技术差异深度总结
python·单片机·嵌入式硬件
李可以量化4 小时前
PTrade 策略入门:before_trading_start 函数详解(上)—— 盘前准备逻辑全指南
python
大海变好AI4 小时前
AIGC分层推理落地能否串联多工具完成自动化闭环
人工智能·python·自动化·aigc
二宝哥5 小时前
14.Python模块与包完全指南:从定义到实战
python
三声三视5 小时前
交互式用够了?用 Agent SDK 把 Claude 塞进 Python Web 服务
人工智能·python·ai·aigc·ai编程
zhanghaha13145 小时前
Python语言基础:4_数据类型转换
java·前端·python
larance6 小时前
机器学习特征预处理之标准化/归一化
开发语言·python·机器学习
tokenova6 小时前
Python 多模型统一调用封装类,一套代码兼容 GPT/Claude/Grok
python