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)
相关推荐
木头程序员几秒前
关于load_data_fashion_mnist函数运行原理以及运行速度慢解决方案
人工智能·python·深度学习·d2l
郝学胜-神的一滴11 分钟前
[力扣 20] 栈解千愁:有效括号序列的优雅实现与深度解析
java·数据结构·c++·算法·leetcode·职场和发展
林姜泽樾11 分钟前
python入门第六课,其他字符串格式化和input
开发语言·python·pycharm
yunpeng.zhou12 分钟前
深度理解agent与llm之间的关系、及mcp与skill的区别
人工智能·python·ai
AlenTech20 分钟前
128. 最长连续序列 - 力扣(LeetCode)
算法·leetcode·职场和发展
田梓燊21 分钟前
leetcode 无重复字符的最长子串
算法·leetcode·职场和发展
智算菩萨28 分钟前
【Pygame】第14章 摄像机系统与游戏视口控制技术
python·游戏·pygame
小镇学者34 分钟前
【python】 macos 安装ffmpeg 命令行工具
python·macos·ffmpeg
电商API&Tina38 分钟前
【京东item_getAPI 】高稳定:API 、非爬虫、不封号、不掉线、大促稳跑
大数据·网络·人工智能·爬虫·python·sql·json
O丶ne丨柒夜1 小时前
Claude Code、Codex 常用命令和命令速查
python