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)
相关推荐
pursuit_csdn15 小时前
LeetCode 1022. Sum of Root To Leaf Binary Numbers
算法·leetcode·深度优先
nimadan1215 小时前
**AI漫剧软件2025推荐,解锁高性价比创意制作新体验**
人工智能·python
踩坑记录17 小时前
leetcode hot100 35. 搜索插入位置 medium 二分查找
leetcode
yunhuibin18 小时前
GoogLeNet学习
人工智能·python·深度学习·神经网络·学习
易辰君19 小时前
【Python爬虫实战】正则:中文匹配与贪婪非贪婪模式详解
开发语言·爬虫·python
秀儿还能再秀19 小时前
正则表达式核心语法 + Python的 re 库中常用方法
python·正则表达式
xcLeigh19 小时前
Python入门:Python3 正则表达式全面学习教程
python·学习·正则表达式·教程·python3
-海绵东东-19 小时前
哈希表······················
算法·leetcode·散列表
多恩Stone20 小时前
【C++ debug】在 VS Code 中无 Attach 调试 Python 调用的 C++ 扩展
开发语言·c++·python
XW010599920 小时前
4-11判断素数
前端·python·算法·素数