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)
相关推荐
曲幽7 小时前
FastAPI 身份验证总踩坑?这份 FastAPI Users “避坑指南”请收好
python·fastapi·web·jwt·oauth2·user·authentication
装不满的克莱因瓶8 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
何以解忧,唯有..8 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
金銀銅鐵8 小时前
用 Tkinter 实现简单的猜数字游戏
后端·python
copyer_xyf8 小时前
Python 模块与包的导入导出
前端·后端·python
8Qi89 小时前
LeetCode 213:打家劫舍 II(House Robber II)—— 题解 ✅
算法·leetcode·职场和发展·动态规划
ice8130331819 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
copyer_xyf9 小时前
Python venv 虚拟环境
前端·后端·python
Lsk_Smion10 小时前
力扣实训 _ [75].颜色分类 _ 杨辉三角
数据结构·算法·leetcode
林爷万福10 小时前
GitHub 开源光谱数据处理项目推荐
python·光纤光谱仪