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)
相关推荐
疯狂成瘾者7 分钟前
增强型大模型代理
python
小李云雾7 分钟前
FastAPI 后端开发:文件上传 + 表单提交
开发语言·python·lua·postman·fastapi
Legend NO248 分钟前
数据资产评估风险识别、分析与管控体系建设
大数据·人工智能·python
llm大模型算法工程师weng13 分钟前
Python敏感词检测方案详解
开发语言·python·c#
Ricky111zzz16 分钟前
leetcode学python记录2
python·算法·leetcode·职场和发展
毕胜客源码19 分钟前
改进yolov8的香蕉成熟度检测系统,改进前后的模型指标对比,有技术文档,支持图像、视频和摄像实时检测
人工智能·python·深度学习·yolo·django
会编程的土豆19 分钟前
【数据结构与算法】堆排序
开发语言·数据结构·c++·算法·leetcode
NeilNiu25 分钟前
lm-Evaluation Harness使用
python
梦幻精灵_cq26 分钟前
我的color()设计理念——终端颜色渲染状态机设定
python
南 阳28 分钟前
Python从入门到精通day62
开发语言·python