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)
相关推荐
努力学习_小白几秒前
数据增强——tensorflow
人工智能·python·tensorflow
m0_694845571 分钟前
marimo搭建教程:替代Jupyter的交互式开发工具
服务器·ide·python·docker·jupyter·github
csdn2015_5 分钟前
Set<String> 类型取第一条记录
开发语言·windows·python
csdn2015_6 分钟前
List<String> 转换为Set<String>
windows·python·list
Chen--Xing10 分钟前
Python -- 正则表达式
python·正则表达式·数据分析·数据脱敏·2025年能源网络安全大赛
l1t18 分钟前
对在aarch64 Linux环境编译安装的CinderX补充测试
linux·运维·服务器·python·jit
getapi22 分钟前
Windows 11 安装 uv包括:更新、常用命令、Python 管理、环境切换等,(Astral 的 Python 包/环境工具)完整指南
windows·python·uv
智算菩萨26 分钟前
【Pygame】第1章 Pygame入门与环境搭建
python·ai编程·pygame
Dxy123931021634 分钟前
Python 使用 `raise` 报错抛出异常显示 Unicode 码如何解决
开发语言·python
Q741_14735 分钟前
每日一题 力扣 3418. 机器人可以获得的最大金币数 力扣 215. 数组中的第K个最大元素 动态规划 TopK问题 C++ 题解
c++·算法·leetcode·动态规划·topk