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)
相关推荐
八月ouc8 分钟前
Python实战小游戏(三): 简易文件管理器
python·shutil·文件管理器·os.walk·pathlib
安冬的码畜日常28 分钟前
【玩转 Postman 接口测试与开发2_020】(完结篇)DIY 实战:随书示例 API 项目本地部署保姆级搭建教程(含完整调试过程)
python·测试工具·django·接口测试·postman·fastapi·api项目
winfredzhang29 分钟前
wxPython实战:打造一个优雅的图片预览工具
chrome·python·预览·剪切板
superman超哥31 分钟前
仓颉GC调优参数深度解析
c语言·开发语言·c++·python·仓颉
Byron Loong36 分钟前
【机器视觉】人物安全距离监测
python·yolo·计算机视觉
Swizard44 分钟前
告别“裸奔”代码:用 Pydantic 让你的 Python 数据固若金汤
python
im_AMBER1 小时前
Leetcode 85 【滑动窗口(不定长)】最多 K 个重复元素的最长子数组
c++·笔记·学习·算法·leetcode·哈希算法
老歌老听老掉牙1 小时前
砂轮轮廓的数学建模与可视化分析
python·数学建模·sympy·砂轮
xoliu11 小时前
Pytorch核心基础入门
人工智能·pytorch·python