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)
相关推荐
️停云️17 小时前
【滑动窗口与双指针】不定长滑动窗口
c++·算法·leetcode·剪枝·哈希
!chen18 小时前
Error: error:0308010C:digital envelope routines::unsupporte
python
小北方城市网19 小时前
分布式锁实战指南:从选型到落地,避开 90% 的坑
java·数据库·redis·分布式·python·缓存
xiaolyuh12319 小时前
【XXL-JOB】 GLUE模式 底层实现原理
java·开发语言·前端·python·xxl-job
likuolei19 小时前
Spring AI框架完整指南
人工智能·python·spring
二哈喇子!19 小时前
PyTorch生态与昇腾平台适配:环境搭建与详细安装指南
人工智能·pytorch·python
Learner19 小时前
Python数据类型(三):列表和元组
开发语言·python
世界唯一最大变量19 小时前
用自创的算法快速解决拉姆奇数
python
leluckys19 小时前
AI- 一种快速实现MCP服务的方法
开发语言·python
写代码的【黑咖啡】20 小时前
探索 Python 中的 Vaex:高效处理大规模数据的新选择
开发语言·python