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)
相关推荐
高频交易dragon11 分钟前
5分钟和30分钟联立进行缠论信号分析
开发语言·python
0思必得013 分钟前
[Web自动化] 开发者工具应用(Application)面板
运维·前端·python·自动化·web自动化·开发者工具
我是华为OD~HR~栗栗呀16 分钟前
华为OD-C面经-23届学院哦
java·c++·python·华为od·华为·面试
资深web全栈开发21 分钟前
LeetCode 3432. 统计元素和差值为偶数的分区方案数
算法·leetcode
xiaozi412023 分钟前
Ruey S. Tsay《时间序列分析》Python实现笔记:综合与应用
开发语言·笔记·python·机器学习
Aspect of twilight24 分钟前
PyTorch DDP分布式训练Pytorch代码讲解
人工智能·pytorch·python
@游子30 分钟前
Python学习笔记-Day5
笔记·python·学习
棒棒的皮皮35 分钟前
【OpenCV】Python图像处理之数字水印
图像处理·python·opencv·计算机视觉
tomeasure37 分钟前
INTERNAL ASSERT FAILED at “/pytorch/c10/cuda/CUDACachingAllocator.cpp“:983
人工智能·pytorch·python·nvidia
追光天使42 分钟前
装饰器的作用
python·装饰器