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)
相关推荐
文丑颜不良啊3 小时前
LeetCode3281~3300题目解析
java·leetcode
kyle~5 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享6 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者6 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
文丑颜不良啊7 小时前
LeetCode3261~3280题目解析
java·leetcode
MSTcheng.7 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人8 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__8 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python
Rain的Java大神之路8 小时前
LeetCode 40 组合总和 II:面试官想听的不是回溯,而是那行去重代码
java·leetcode·面试
用户0332126663679 小时前
使用 Python 轻松移除 Excel 文档中的重复行
python·excel