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)
相关推荐
IT北辰12 分钟前
【Python实战升级版】企业用电深度分析完整版|十大可视化图表+智慧能源看板,电费优化/数据汇报
python
VT.馒头1 小时前
【力扣】2622. 有时间限制的缓存
javascript·算法·leetcode·缓存·typescript
小白学大数据1 小时前
爬虫技术选股:Python 自动化筛选潜力股
开发语言·爬虫·python·自动化
践行见远1 小时前
django之认证与权限
python·django
独自破碎E1 小时前
【新视角】输出二叉树的右视图
leetcode
青春不败 177-3266-05202 小时前
基于R语言lavaan结构方程模型(SEM)实践技术应用
python·r语言·贝叶斯·生态学·结构方程·sem
费弗里2 小时前
进阶技巧:在Dash应用中直接使用原生React组件
python·dash
Ashley_Amanda2 小时前
Python入门知识点梳理
开发语言·windows·python
Ka1Yan2 小时前
[链表] - 代码随想录 160. 相交链表
算法·leetcode·链表
tjjucheng2 小时前
小程序定制开发哪家有完整流程
python