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)
相关推荐
测试19982 小时前
功能测试、自动化测试、性能测试的区别
自动化测试·python·功能测试·测试工具·职场和发展·性能测试·安全性测试
Data_agent2 小时前
1688获得1688店铺所有商品API,python请求示例
java·开发语言·python
一晌小贪欢2 小时前
【Python办公】-图片批量添加文字水印(附代码)
开发语言·python·图片水印·python水印·python添加水印·图片添加水印
海上飞猪2 小时前
【python】基础数据类型
python
万邦科技Lafite3 小时前
一键获取淘宝关键词商品信息指南
开发语言·数据库·python·商品信息·开放api·电商开放平台
Jurio.3 小时前
Python Ray 分布式计算应用
linux·开发语言·python·深度学习·机器学习
爱加糖的橙子3 小时前
Dify升级到Dify v1.10.1-fix修复CVE-2025-55182漏洞
人工智能·python·ai
Pyeako3 小时前
python网络爬虫
开发语言·爬虫·python·requsets库
diegoXie3 小时前
【Python】 中的 * 与 **:Packing 与 Unpacking
开发语言·windows·python