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)
相关推荐
6Hzlia14 小时前
【Hot 100 刷题计划】 LeetCode 15. 三数之和 | C++ 排序+双指针
c++·算法·leetcode
2601_9561394214 小时前
文旅行业品牌全案公司哪家强
大数据·人工智能·python
hrhcode14 小时前
【LangGraph】二.State 和 Node 的设计细节
python·ai·langchain·langgraph·ai框架
dfdfadffa15 小时前
如何创建仅在首次订阅时执行一次计算的 RxJS 懒加载 Observable
jvm·数据库·python
m0_6245785915 小时前
SQL分组后如何计算移动平均值_利用窗口函数AVG配合ROWS
jvm·数据库·python
2401_8242226915 小时前
如何修复待办事项列表无法添加任务的 JavaScript 错误
jvm·数据库·python
CHANG_THE_WORLD15 小时前
<Fluent Python > Unicode 文本与字节
开发语言·python
测试员周周15 小时前
【AI测试系统】第1篇:LangGraph 实战:用 State Graph 搭建 AI测试流水线(4 步编排 + RAG 增强 + 完整代码)
linux·windows·python·功能测试·microsoft·单元测试·多轮对话
噜噜噜阿鲁~15 小时前
python学习笔记 | 8.2、函数式编程-返回函数
笔记·python·学习