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)
相关推荐
quikai198126 分钟前
python练习第三组
开发语言·python
ULTRA??1 小时前
初学protobuf,C++应用例子(AI辅助)
c++·python
CHANG_THE_WORLD2 小时前
Python 字符串全面解析
开发语言·python
努力学算法的蒟蒻2 小时前
day27(12.7)——leetcode面试经典150
算法·leetcode·面试
甄心爱学习2 小时前
CSP认证 备考(python)
数据结构·python·算法·动态规划
databook3 小时前
数据会说谎?三大推断方法帮你“审问”数据真相
后端·python·数据分析
是Dream呀3 小时前
Python圣诞特辑:打造一棵会唱歌、会下雪的魔法圣诞树
开发语言·python·pygame
威哥爱编程3 小时前
使用 TRAE SOLO 一分钟写个简易版飞机大战
python·trae·solo
AndrewHZ3 小时前
【遥感图像入门】DEM数据处理核心算法与Python实操指南
图像处理·python·算法·dem·高程数据·遥感图像·差值算法
CoderYanger3 小时前
动态规划算法-子序列问题(数组中不连续的一段):28.摆动序列
java·算法·leetcode·动态规划·1024程序员节