技术栈

Python | Leetcode Python题解之第514题自由之路

Mopes__2024-10-28 19:38

题目:

题解:

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)
上一篇:考研要求掌握的C语言程度(堆排序)1
下一篇:【代码随想录Day53】图论Part05
相关推荐
Cemtery116
1 天前
Day26 常见的降维算法
人工智能·python·算法·机器学习
星空椰
1 天前
快速掌握FastAPI:高效构建Web API
python·fastapi
塔尖尖儿
1 天前
Python中range()到底是什么演示
python
Ethan-D
1 天前
#每日一题19 回溯 + 全排列思想
java·开发语言·python·算法·leetcode
橘颂TA
1 天前
【剑斩OFFER】算法的暴力美学——LeetCode 733 题:图像渲染
算法·leetcode·职场和发展
weixin_44693403
1 天前
统计学中“in sample test”与“out of sample”有何区别?
人工智能·python·深度学习·机器学习·计算机视觉
weixin_46244623
1 天前
使用 Python 测试 Mermaid 与 Graphviz 图表生成(支持中文)
python·mermaid·graphviz
JOBkiller123
1 天前
钢绞线缺陷检测与识别_Cascade-Mask-RCNN_RegNetX模型训练与应用实战
python
nvd11
1 天前
深入 ReAct Agent 的灵魂拷问:从幻觉到精准执行的调试实录
python·langchain
热门推荐
01GitHub 镜像站点02OpenCode 入门教程:介绍 · 安装 · 配置第三方 API (如 Claude)032025 Telegram 最新免费社工库机器人(LetsTG可[特殊字符])搭建指南(含 Python 脚本)04Linux下V2Ray安装配置指南05安娜的档案(Anna’s Archive) 镜像网站/国内最新可访问入口(持续更新)06UV安装并设置国内源07AI 规范驱动开发“三剑客”深度对比:Spec-Kit、Kiro 与 OpenSpec 实战指南08BongoCat - 跨平台键盘猫动画工具09Claude Code Skills 实用使用手册10网站改了域名,如何查找?