技术栈

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
相关推荐
We་ct
1 天前
LeetCode 5. 最长回文子串:DP + 中心扩展
前端·javascript·算法·leetcode·typescript
做怪小疯子
1 天前
华为笔试0429
python·numpy
Warson_L
1 天前
Dictionary
python
寒山李白
1 天前
解决 python-docx 生成的 Word 文档打开时弹出“无法读取内容“警告
python·word·wps·文档·docx·qoder
leoufung
1 天前
LeetCode 149: Max Points on a Line - 解题思路详解
算法·leetcode·职场和发展
样例过了就是过了
1 天前
LeetCode热题100 最长公共子序列
c++·算法·leetcode·动态规划
2401_83236552
1 天前
JavaScript中rest参数(...args)取代arguments的优势
jvm·数据库·python
Sirius.z
1 天前
第J3周:DenseNet121算法详解
python
2301_77962241
1 天前
Go语言怎么用信号量控制并发_Go语言semaphore信号量教程【入门】
jvm·数据库·python
2301_76628344
1 天前
c++如何将控制台输出保存到文件_cout重定向到txt【详解】
jvm·数据库·python
热门推荐
01要裂开了!ChatGPT要手机号验证了?注册Codex要求验证电话号码怎么办?2026年登陆Codex要手机号验证的解决办法02GitHub 镜像站点03Codex 接入 DeepSeek API 完整配置文档04裂开!ChatGPT 居然开始要手机号验证,附详细解决方法05【AI】2026 年具身智能模型和世界模型总结06零基础教你claude code 接入 deepseek V4072026年AI前瞻:量子AI、具身智能与科学发现的新纪元08在Windows 11上安装Docker的踩坑记录09实测可用|小米 MiMo 百万亿 Token 免费领,开发者速冲10CC-Switch & Claude 基于 Linux 服务器安装使用指南