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)
相关推荐
小趴蔡ha2 小时前
02 Anaconda、Python 与机器学习开发环境入门
python·机器学习·anaconda
2401_868534782 小时前
RTOS之RT-Thread & Linux:线程/进程管理与调度核心差异分析
c++·python
mifengxing3 小时前
LeetCode 41.缺失的第一个正数|Hard题O(n)+O(1)最优解法深度解析
java·算法·leetcode·排序算法
数字化转型分享点滴3 小时前
富士康、蓝思科技为何选择四化信息?MES制造执行系统的实践
python·科技
wling03013 小时前
vasp虚频计算-python脚本
开发语言·windows·python·vasp计算
魔镜前的帅比3 小时前
(开源项目)x-claw(总)
python·ai·rust·开源
xrandzj4 小时前
Python面向对象编程入门:类、实例、初始化与封装实践
开发语言·python
matlabgoodboy7 小时前
计算机毕设代做|Java Python Matlab APP 全套开发设计
java·python·课程设计
用户8356290780517 小时前
Python Word 转 PDF 和 PDF 转 Word 指南
后端·python
用户8356290780517 小时前
如何使用 Python 加密和保护 Word 文档
后端·python