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)
相关推荐
忘忧记2 分钟前
pytest进阶参数化用法
前端·python·pytest
眼眸流转6 分钟前
LeetCode热题100(七)
算法·leetcode·c#
JavaWeb学起来9 分钟前
Python学习教程(二)字符串
开发语言·python·python基础
归寻太乙13 分钟前
2026年03月27日—Python基础—Python背景知识与环境搭建
开发语言·python
独隅16 分钟前
PyTorch 的全面介绍
人工智能·pytorch·python
小陈工17 分钟前
Python后端实战:GraphQL高级应用与性能优化全解析
开发语言·人工智能·后端·python·性能优化·开源·graphql
代码探秘者19 分钟前
【大模型应用】一篇弄懂Skill
数据结构·数据库·python·算法·spring
阿Y加油吧25 分钟前
算法高频压轴题|滑动窗口最大值 + 最小覆盖子串,单调队列 + 滑动窗口双杀
数据结构·算法·leetcode
运维行者_33 分钟前
Applications Manager 中的 Azure 监控
运维·服务器·网络·数据库·后端·python·flask
2501_9383134037 分钟前
用Python实现自动化的Web测试(Selenium)
前端·python·自动化