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)
相关推荐
2401_8414956424 分钟前
【Python高级编程】Python 核心语法速查演示
python·字符串·集合·列表·元组·字典·运算符
Swift社区39 分钟前
LeetCode 460 - LFU 缓存
算法·leetcode·缓存
2301_811958381 小时前
服务器自己账号下安装conda
linux·python·conda
百***78751 小时前
Mistral 3极速接入指南:3步上手+核心能力解析+避坑手册
人工智能·python·开源
LCG米1 小时前
嵌入式Python开发:MicroPython在物联网硬件上的实战应用案例
python·单片机·物联网
nvd111 小时前
SQLAlchemy 2.0 类型注解指南:`Mapped` 与 `mapped_column`
python
让学习成为一种生活方式1 小时前
AGAT v1.6.0 安装与使用--生信工具72
人工智能·python·机器学习
小陈phd1 小时前
Python MCP 工具开发入门:Server、Client 和 LLM 集成
开发语言·python·github
ShenLiang20251 小时前
识别SQL里的列名
大数据·人工智能·python
jijkck1 小时前
python库--pyautogui————windows模拟鼠标键盘、图像自动匹配、按钮弹窗
python·windows 10