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)
相关推荐
程序媛一枚~1 天前
✨✨✨使用Python,OpenCV及图片拼接生成❤️LOVE❤️字样图,每张小图加随机颜色边框,大图加随机大小随机颜色边框
图像处理·python·opencv·numpy·图像拼接
Charlie_lll1 天前
力扣解题-637. 二叉树的层平均值
算法·leetcode
MediaTea1 天前
Python:collections.Counter 常用函数及应用
开发语言·python
如若1231 天前
flash-attn 安装失败?从报错到成功的完整排雷指南(CUDA 12.8 + PyTorch 2.7)
人工智能·pytorch·python
007张三丰1 天前
知乎高赞回答爬虫:从零开始,建立你的专属知识库
爬虫·python·知识库·python爬虫·知乎·高赞回答
李昊哲小课1 天前
Python json模块完整教程
开发语言·python·json
易醒是好梦1 天前
Python flask demo
开发语言·python·flask
怪侠_岭南一只猿1 天前
爬虫工程师入门阶段一:基础知识点完全学习文档
css·爬虫·python·学习·html
滴滴答滴答答1 天前
机考刷题之 6 LeetCode 169 多数元素
算法·leetcode·职场和发展
圣保罗的大教堂1 天前
leetcode 1980. 找出不同的二进制字符串 中等
leetcode