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)
相关推荐
rgeshfgreh12 分钟前
Python流程控制:从条件到循环实战
前端·数据库·python
luoluoal16 分钟前
基于python大数据的电影市场预测分析(源码+文档)
python·mysql·django·毕业设计·源码
幻云201027 分钟前
Python深度学习:从入门到实战
人工智能·python
Zoey的笔记本1 小时前
敏捷与稳定并行:Scrum看板+BPM工具选型指南
大数据·前端·数据库·python·低代码
im_AMBER1 小时前
Leetcode 102 反转链表
数据结构·c++·学习·算法·leetcode·链表
朔北之忘 Clancy2 小时前
2025 年 9 月青少年软编等考 C 语言一级真题解析
c语言·开发语言·c++·学习·数学·青少年编程·题解
开开心心就好2 小时前
图片格式转换工具,右键菜单一键转换简化
linux·运维·服务器·python·django·pdf·1024程序员节
骥龙2 小时前
1.2下、工欲善其事:物联网安全研究环境搭建指南
python·物联网·安全
AlenTech2 小时前
200. 岛屿数量 - 力扣(LeetCode)
算法·leetcode·职场和发展
Lxinccode2 小时前
BUG(20) : response.text耗时很久, linux耗时十几秒, Windows耗时零点几秒
python·bug·requests·response.text·response.text慢