技术栈

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
相关推荐
big_rabbit0502
1 小时前
[算法][力扣222]完全二叉树的节点个数
数据结构·算法·leetcode
张李浩
2 小时前
Leetcode 15三题之和
算法·leetcode·职场和发展
坐吃山猪
2 小时前
Python进度条
linux·服务器·python
l1t
2 小时前
四种python工具包用SQL查询csv和parquet文件的方法比较
大数据·python·sql
清水白石008
2 小时前
Python 并发三剑客:多线程、多进程与协程的实战抉择
java·服务器·python
2301_79380469
2 小时前
更优雅的测试:Pytest框架入门
jvm·数据库·python
dinl_vin
2 小时前
python:常用的基础工具包
开发语言·python
x_xbx
2 小时前
LeetCode:206. 反转链表
算法·leetcode·链表
abant2
2 小时前
leetcode 138 复制随机链表
算法·leetcode·链表
wefly2017
3 小时前
无需安装、开箱即用!m3u8live.cn 在线 HLS 播放器,调试直播流效率翻倍
前端·后端·python·前端开发工具·后端开发工具
热门推荐
01GitHub 镜像站点02Qwen3.5 开源全解析:从 0.8B 到 397B,代际升级 + 全场景选型指南03OpenClaw 使用和管理 MCP 完全指南04UV安装并设置国内源05OpenClaw Control UI安全上下文访问配置06小黑课堂计算机二级WPSoffice题库软件下载安装教程(2026年3月最新版)07Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services08本地部署 OpenClaw + DeepSeek-R1 完全指南09OpenClaw macOS 完整安装与本地模型配置教程(实战版)10AI 编程三剑客:Spec-Kit、OpenSpec、Superpowers 深度对比与实战指南