技术栈

Python | Leetcode Python题解之第514题自由之路

Mopes__2024-10-28 19:38

题目:

题解:

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)
上一篇:考研要求掌握的C语言程度(堆排序)1
下一篇:【代码随想录Day53】图论Part05
相关推荐
RopenYuan
18 分钟前
FastAPI -API Router的应用
前端·网络·python
听风吹等浪起
20 分钟前
用Python和Pygame从零实现坦克大战
开发语言·python·pygame
Kk.0802
29 分钟前
力扣 LCR 084.全排列||
算法·leetcode·职场和发展
书到用时方恨少!
39 分钟前
Python Pandas 使用指南:数据分析的瑞士军刀
python·数据分析·pandas
旖-旎
42 分钟前
分治(快速选择算法)(3)
c++·算法·leetcode·排序算法·快速选择
_日拱一卒
1 小时前
LeetCode:合并区间
算法·leetcode·职场和发展
智算菩萨
1 小时前
【Pygame】第8章 文字渲染与字体系统(支持中文字体)
开发语言·python·pygame
:mnong
1 小时前
全图纸语义理解升级分析
python·openvino·paddleocr·qt6.3·paddleocr-vl
qh0526wy
2 小时前
pathlib 核心功能一览
python
Hello eveybody
2 小时前
PyCharm性能调优避坑录
python·pycharm
热门推荐
01GitHub 镜像站点02Qwen3.5-Omni与Qwen3.6模型全面解析(含测评/案例/使用教程)032026年3月AI领域大事件:DeepSeek引领开源风暴04VMware Workstation Pro 17 虚拟机完整安装教程(2026最新)05AI 编程效率翻倍:Superpowers Skills 上手清单 + 完整指南06Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services07UV安装并设置国内源08【技术干货】Gemma 4 上手深度指南:本地多模态大模型的新基线09Mac 本地部署 OMLX + 通义千问 Qwen3.5-27B 保姆级教程10纯 HTML/CSS/JS 实现的高颜值登录页,还会眨眼睛!少女心爆棚!