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)
相关推荐
Aurorar0rua19 分钟前
CS50 x 2024 Notes Python - 02
开发语言·python·学习方法
樱桃木25 分钟前
回测可信度审查:样本外测试的五种常见自欺
python
zyseo828 分钟前
谷歌SEO 网站迁移 301 映射脚本:旧站 URL 自动匹配新站结构
开发语言·python
伞伞悦读30 分钟前
【第59期】转置不是摆好看:Python 矩阵乘法、逆矩阵与线性方程组
python
Dmz丶35 分钟前
前端转 AI 100 天 Day 29:Nginx 反代 + HTTPS——让服务“能上公网“
python
麦序子42 分钟前
用 Python + python-docx 批量生成带表格样式的装修报价单 Word 文档(含合计公式)
开发语言·python·自然语言处理·word·python3.11
文丑颜不良啊43 分钟前
LeetCode476~500题目解析
java·leetcode
1-1=01 小时前
Python PyCharm
开发语言·python·pycharm
梦影_1 小时前
Langchain简单快速上手教程(九)—— 核心组件之少样本提示
人工智能·python·自然语言处理·中间件·langchain
机械设计扫地僧1 小时前
用PYTHON工具对FAG INA CS 系列薄壁轴承进行初步选型筛选
python