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)
相关推荐
布吉岛的石头28 分钟前
Java 程序员第 22 阶段:Function Call 工具调用实战,Java 封装大模型外部能力
java·人工智能·python
l1t33 分钟前
DeepSeek总结的使用实体-组件-系统和基于存在性处理进行Python编程简介
开发语言·python
曲幽39 分钟前
FastApiAdmin 后端接口开发好了,前端管理界面怎么调用与显示?
python·vue3·api·fastapi·web·ant design·view·menu·frontend
rayyy91 小时前
神经网络模型的外推性验证
pytorch·python·深度学习
长乐呀1 小时前
数据集获取与整理
python
清水白石0081 小时前
从脚本到系统:设计一个支持插件、限流、重试与监控的 Python 异步爬虫框架
网络·爬虫·python
deepin_sir1 小时前
02 - 第一个 Python 程序
开发语言·python
徐先生 @_@|||1 小时前
pycharm/IDEA + markdown + 图床(PicList)
ide·python·pycharm·intellij-idea
csdn_aspnet1 小时前
C++ 算法 LeetCode 编号 70 - 爬楼梯
开发语言·c++·算法·leetcode
ZHW_AI课题组1 小时前
基于PCA与HOG特征融合的热轧钢带缺陷检测
人工智能·python·机器学习