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)
相关推荐
jufeng13077 小时前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 11 篇】
python·ai agent·mcp
想吃火锅10057 小时前
【leetcode】200. 岛屿数量
算法·leetcode·职场和发展
En^_^Joy7 小时前
Django项目配置全攻略:settings配置文件
后端·python·django
Nil2087 小时前
leetcode 54螺旋矩阵
算法·leetcode·矩阵
for_ever_love__8 小时前
python基础语法学习: 异常的传递性
开发语言·python·学习
AC赳赳老秦8 小时前
公开图片 OCR 数据提取:OpenClaw 合规采集公开信息图,识别文字与表格并转化为结构化数据
java·大数据·前端·数据库·python·php·openclaw
麻雀飞吧9 小时前
零基础选量化工具,先把问题说清楚
人工智能·python
段一凡-华北理工大学9 小时前
AI推动工业智能化转型~系列文章20:工业 AI 平台架构:云-边-端协同的技术体系
人工智能·python·架构·工业平台·云-边协同
CodeBlog-star9 小时前
Harness Engineering:Pi Agent 架构深度解析
人工智能·python·架构·harness工程