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)
相关推荐
小江的记录本1 天前
【JVM虚拟机】垃圾回收GC:四种引用类型:强引用、软引用、弱引用、虚引用(附《思维导图》+《面试高频考点清单》)
java·jvm·spring boot·后端·python·spring·面试
圣保罗的大教堂1 天前
leetcode 2540. 最小公共值 简单
leetcode
APIshop1 天前
Python 获取 1688 商品采集 API 接口 | 工厂货源自动化对接商品信息 | 无需选品
运维·python·自动化
deepin_sir1 天前
10 - 函数
开发语言·python
charlee441 天前
《GIS基础原理与技术实践》配套案例(Python版)
python·conda·numpy·gis·环境配置
枫叶林FYL1 天前
项目十:事件溯源仓储管理系统(WMS)仿真实现
开发语言·python
渣渣xiong1 天前
从零开始:前端转型AI agent直到就业第五十七天-第五十八天
前端·人工智能·python
小L~~~1 天前
基于贪心策略的混合遗传算法求解01背包问题
python·算法
才兄说1 天前
机器人二次开发机器人动作定制?动作迁移数据优化
python
洛水水1 天前
【力扣100题】53.最长回文子串
算法·leetcode·职场和发展