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)
相关推荐
落羽凉笙2 小时前
Python学习笔记(3)|数据类型、变量与运算符:夯实基础,从入门到避坑(附图解+代码)
笔记·python·学习
Quintus五等升2 小时前
深度学习①|线性回归的实现
人工智能·python·深度学习·学习·机器学习·回归·线性回归
天远Date Lab2 小时前
Python实战:对接天远数据手机号码归属地API,实现精准用户分群与本地化运营
大数据·开发语言·python
哈里谢顿2 小时前
Python异常链:谁才是罪魁祸首?一探"The above exception"的时间顺序
python
AlenTech3 小时前
160. 相交链表 - 力扣(LeetCode)
数据结构·leetcode·链表
哈里谢顿3 小时前
验证 list() 会调用 `__len__` 方法的深度解析
python·django
vibag3 小时前
构建智能体与工具调用
python·语言模型·大模型·langgraph
sin_hielo3 小时前
leetcode 1161(BFS)
数据结构·算法·leetcode
小途软件3 小时前
高校宿舍访客预约管理平台开发
java·人工智能·pytorch·python·深度学习·语言模型
-dcr3 小时前
49.python自动化
运维·python·自动化