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)
相关推荐
weixin_4624462312 分钟前
使用 Tornado + systemd 搭建图片静态服务(imgserver)
开发语言·python·tornado
别多香了18 分钟前
python基础之面向对象&异常捕获
开发语言·python
youngee1118 分钟前
hot100-61电话号码的字母组合
java·数据结构·leetcode
POLITE323 分钟前
Leetcode 76.最小覆盖子串 JavaScript (Day 6)
javascript·算法·leetcode
Silence_Jy24 分钟前
Kimi K2技术报告
人工智能·python·深度学习·transformer
AI Echoes28 分钟前
自定义 LangChain 文档加载器使用技巧
数据库·人工智能·python·langchain·prompt·agent
未来之窗软件服务1 小时前
幽冥大陆(八十五)Python 水果识别ONNX转手机mobile —东方仙盟练气期
开发语言·python·模型训练·仙盟创梦ide·东方仙盟
莓有烦恼吖1 小时前
基于AI图像识别与智能推荐的校园食堂评价系统研究 05-审核机制模块
java·服务器·python
linghuocaishui1 小时前
京东用工平台实践:亲测案例复盘分享
人工智能·python