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)
相关推荐
weixin_433179331 小时前
Python - word jumble游戏
开发语言·python
Iridescent11212 小时前
Iridescent:Day48
python
BBB努力学习程序设计2 小时前
Python迭代器与生成器:优雅的惰性计算艺术
python
BBB努力学习程序设计2 小时前
Python描述符协议:属性访问的底层魔法
python
qq_317620312 小时前
第00章-Python学习大纲
python·python入门
Hello.Reader2 小时前
Table & SQL API 配置从“默认可用”到“针对场景调优”的一套方法论
数据库·python·sql
BoBoZz192 小时前
VTKWithNumpy使用 NumPy 数组来创建3D体渲染所需要的数据
python·vtk·图形渲染·图形处理
Coder_Boy_2 小时前
Java调用Python实现FAISS向量操作(两种方式完整实战)
java·python·faiss
木昆子2 小时前
AI Agent案例实践:三种智能体开发模式详解之一(手写代码)
后端·python
0和1的舞者3 小时前
接口自动化测试详解(二):requests 请求封装与 Pytest 框架全实战
开发语言·自动化测试·python·测试开发·接口·测试