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)
相关推荐
卡尔曼的BD SLAMer11 分钟前
计算机视觉与深度学习 | Python实现EMD-SSA-VMD-LSTM时间序列预测(完整源码和数据)
python·深度学习·算法·cnn·lstm
nuclear20111 小时前
使用Python将 Excel 中的图表、形状和其他元素导出为图片
python·excel·将excel图表转换为图片·将excel文本框转换为图片
小袁拒绝摆烂3 小时前
OpenCV-python灰度变化和直方图修正类型
python·opencv·计算机视觉
Dxy12393102166 小时前
Python 条件语句详解
开发语言·python
龙泉寺天下行走6 小时前
Python 翻译词典小程序
python·oracle·小程序
践行见远7 小时前
django之视图
python·django·drf
love530love8 小时前
Windows避坑部署CosyVoice多语言大语言模型
人工智能·windows·python·语言模型·自然语言处理·pycharm
掘金-我是哪吒9 小时前
分布式微服务系统架构第132集:Python大模型,fastapi项目-Jeskson文档-微服务分布式系统架构
分布式·python·微服务·架构·系统架构
飞川撸码9 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
xhdll10 小时前
egpo进行train_egpo训练时,keyvalueError:“replay_sequence_length“
python·egpo