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)
相关推荐
cui_ruicheng12 分钟前
Python从入门到实战(十六):多进程编程
开发语言·python
_Jimmy_2 小时前
FastAPI + SQLAlchemy全局事务管理
python·fastapi
用户8356290780512 小时前
如何使用 Python 在 Excel 中添加、编辑和删除超链接
后端·python
AC赳赳老秦4 小时前
企业工商公开信息采集分析:OpenClaw 批量查询企业工商信息,生成企业画像报告
大数据·开发语言·python·自动化·php·deepseek·openclaw
FoldWinCard4 小时前
D6 Python 基础语法 --- 保留关键字
开发语言·python
暮暮祈安5 小时前
Celery 新手入门指南
java·数据库·python·flask·httpx
JustNow_Man5 小时前
每日高频场景英文口语
python
风吹心凉5 小时前
python3基础2026.7.22
开发语言·python
程序猿乐锅6 小时前
【数据结构与算法 | 第六篇】力扣1109,1094差分数组
java·算法·leetcode
小猴子爱上树7 小时前
一站式解决图片视频翻译难题的高效AI工具
人工智能·python·音视频