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)
相关推荐
旦莫16 分钟前
Pytest教程:Pytest与主流测试框架对比
人工智能·python·pytest
数据大魔方27 分钟前
【期货量化实战】螺纹钢量化交易指南:品种特性与策略实战(TqSdk完整方案)
python·算法·github·程序员创富·期货程序化·期货量化·交易策略实战
独自破碎E33 分钟前
二分查找-I
leetcode
旻璿gg44 分钟前
paddleocr、paddleocrvl、ppocrv5
python
清水白石0081 小时前
手写超速 CSV 解析器:利用 multiprocessing 与 mmap 实现 10 倍 Pandas 加速
python·pandas
千金裘换酒1 小时前
LeetCode 删除链表的倒数第N个结点
算法·leetcode
Corleo1 小时前
记录一次复杂的 ONNX 到 TensorRT 动态 Shape 转换排错过程
python·ai
shughui1 小时前
Python基础面试题:语言定位+数据类型+核心操作+算法实战(含代码实例)
开发语言·python·算法
No0d1es1 小时前
2025年12月电子学会青少年软件编程Python六级等级考试真题试卷
开发语言·python·青少年编程·等级考试·电子学会
Blossom.1182 小时前
Transformer架构优化实战:从MHA到MQA/GQA的显存革命
人工智能·python·深度学习·react.js·架构·aigc·transformer