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)
相关推荐
用户03321266636723 分钟前
快速合并 Word 文档【Python 指南】
python
威联通网络存储26 分钟前
TS-h987XU-RP 在化工制造批次数据场景的部署
python·制造
m0_5474866635 分钟前
《Python爬虫大数据采集与挖掘》全套PPT课件2026
爬虫·python·powerpoint
CV山月1 小时前
《DPO 算法详解:不训练奖励模型,如何让大模型直接学会人类偏好?》
人工智能·经验分享·python·大模型·强化学习·研究生
ctlover1 小时前
网络编程和多线程
开发语言·网络·python
Mr_liu_6661 小时前
ns3-gym例子解析_基础例子与wifi例子_DQN(3)
开发语言·c++·python·dqn·ns3
weixin_440730501 小时前
playwright实战-渠道应用操作
开发语言·前端·python
asdzx671 小时前
Python 解析 Excel 数据、图片与图表的实现方案
python·excel
砚底藏山河1 小时前
存储选型实战:CSV-SQLite-MySQL同机基准(魔码量化实战 #02)
java·数据库·python·金融·maven
土司大王1 小时前
LeetCode hot100——实现 Trie (前缀树)
java·算法·leetcode