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)
相关推荐
波诺波3 分钟前
项目pid-control-simulation-main 中的 main.py 代码讲解
开发语言·python
巧妹儿25 分钟前
Python 配置管理封神技:pydantic_settings+@lru_cache,支持优先级,安全又高效,杜绝重复加载!
开发语言·python·ai·配置管理
参.商.26 分钟前
【Day43】49. 字母异位词分组
leetcode·golang
独隅29 分钟前
Python AI 全面使用指南:从数据基石到智能决策
开发语言·人工智能·python
胡耀超33 分钟前
Web Crawling 网络爬虫全景:技术体系、反爬对抗与全链路成本分析
前端·爬虫·python·网络爬虫·数据采集·逆向工程·反爬虫
小陈的进阶之路37 分钟前
Selenium元素定位
python·selenium
李昊哲小课37 分钟前
matplotlib多子图与复杂布局实战
python·数据分析·matplotlib·数据可视化
2401_8319207438 分钟前
持续集成/持续部署(CI/CD) for Python
jvm·数据库·python
写代码的【黑咖啡】43 分钟前
Python Web 开发新宠:FastAPI 全面指南
前端·python·fastapi
吴佳浩 Alben1 小时前
GPU 编号错乱踩坑指南:PyTorch cuda 编号与 nvidia-smi 不一致
人工智能·pytorch·python·深度学习·神经网络·语言模型·自然语言处理