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)
相关推荐
人工智能AI技术31 分钟前
【Agent从入门到实践】25 主流向量数据库速览:Pinecone、Chroma、Milvus,本地/云端选型建议
人工智能·python
电商API&Tina1 小时前
Python请求淘宝商品评论API接口全指南||taobao评论API
java·开发语言·数据库·python·json·php
多米Domi0111 小时前
0x3f 第40天 setnx的分布式锁和redission,写了一天项目书,光背了会儿八股,回溯(单词搜索)
数据结构·算法·leetcode
地球没有花1 小时前
调整warmup的batch优化tensorflow serving P99耗时毛刺
人工智能·python·tensorflow
梭七y1 小时前
【力扣hot100题】(151)课程表
算法·leetcode·哈希算法
hhy_smile2 小时前
Python environment and installation
开发语言·python
一分之二~2 小时前
二叉树--求最小深度(迭代和递归)
数据结构·c++·算法·leetcode·深度优先
老鼠只爱大米2 小时前
LeetCode经典算法面试题 #24:两两交换链表中的节点(迭代法、递归法等多种实现方案详细解析)
算法·leetcode·链表·递归·双指针·迭代·链表交换
莫非王土也非王臣3 小时前
网页端的TensorFlow开发实践
人工智能·python·tensorflow
喵手3 小时前
Python爬虫零基础入门【第七章:动态页面入门(Playwright)·第3节】优先 API:用 Network 找接口,回到 Requests(更稳定)!
爬虫·python·playwright·python爬虫实战·python爬虫工程化实战·python爬虫零基础入门·优先 api