技术栈

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
相关推荐
赵民勇
21 分钟前
Python 协程详解与技巧总结
python
极光代码工作室
33 分钟前
基于YOLO目标检测的智能监控系统
python·深度学习·yolo·机器学习·计算机视觉
江华森
1 小时前
Python 进阶编程实战 — 从多版本环境到百万级登录系统
python
C+-C资深大佬
1 小时前
python while循环
服务器·开发语言·python
wabs666
2 小时前
关于动态规划【力扣1143.最长公共子序列的思考】
算法·leetcode·动态规划
剑挑星河月
2 小时前
54.螺旋矩阵
java·算法·leetcode·矩阵
zh路西法
2 小时前
【现代控制理论与卡尔曼滤波】从状态空间到Python仿真实现
开发语言·python
Vodka~
3 小时前
WSL2 + RViz GPU渲染机械臂
人工智能·python
8Qi8
3 小时前
hello-agents学习笔记--Memory让Agent拥有记忆
人工智能·python·llm·agent·ai编程·vibecoding
Esaka_Forever
3 小时前
Python 完整内存管理机制详解
开发语言·python·spring
热门推荐
01GitHub 镜像站点022026 年 AI 编程工具终极横评:Cursor vs Claude Code vs Copilot vs Windsurf03AI科技热点日报 | 2026年07月01日04【AI】2026 年具身智能模型和世界模型总结052026 AI 编程工具终极实战指南:Cursor vs Claude Code vs Copilot,开发者该怎么选?062026 年 AI 大模型 & AI 编程工具实战全总结072026年6月AI大模型全景报告:GPT-5.6、Claude Opus 4.8、Gemini 3.5,中美AI三足鼎立谁主沉浮?08Claude Code、Codex、Cursor三分天下:2026年AI编程Agent生态全景剖析09Agnes AI 免费 API 接入指南:文本、生图、生视频,一套接口全免费102026 国产 AI 大模型横评:DeepSeek、通义千问、Kimi、文心一言、星火、豆包谁更能打?