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)
相关推荐
用户83562907805116 分钟前
使用 Python 在 Excel 中添加和自定义文本框
后端·python
总裁余(余登武)44 分钟前
python多个py文件打包【解决exe不能移动运行bug】
python
卡提西亚1 小时前
leetcode-1438. 绝对差不超过限制的最长连续子数组
算法·leetcode·职场和发展
Java面试题总结1 小时前
LeetCode 93.复原IP地址
算法·leetcode·职场和发展·.net
kisloy1 小时前
【python零基础教程第24讲】代码规范与质量管控
开发语言·python
xywww1682 小时前
AWS 账号权限怎么分:根用户和 IAM 用户区别及日常使用建议
大数据·开发语言·人工智能·python·gpt·云计算·aws
许彰午3 小时前
100_Python面试常见问题汇总
java·python·面试
皓悦编程记3 小时前
【YOLO26 系列】基于YOLO26的垃圾分类检测系统【python源码+Pyqt5界面/WEB+数据集+训练代码】
python·qt·分类
滴滴滴嘟嘟嘟.3 小时前
强化学习消融实验-batch_size / clip_range / gae_lambda / lr
python·机器学习
2601_963932984 小时前
怀孕四个月能做流产吗?中期妊娠终止方式与子宫修护科普指南
python