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)
相关推荐
初九之潜龙勿用几秒前
GMM NZ 全流程详解实战:FSDP MOE 训练加速
人工智能·pytorch·python
山土成旧客几秒前
【Python学习打卡-Day28】类的蓝图:从模板到对象的构建艺术
linux·python·学习
Mqh1807624 分钟前
day47 预训练模型
python
乙酸氧铍11 分钟前
python实现gif图片缩放,支持透明像素
图像处理·python·gif·pil
q_302381955615 分钟前
14.7MB轻量模型!NVIDIA Jetson边缘设备解锁工厂设备故障预警新方案
人工智能·python·算法·ascend·算子开发
Niuguangshuo24 分钟前
PyTorch优化器完全指南
人工智能·pytorch·python
38242782724 分钟前
python:yield用法
开发语言·python
STLearner30 分钟前
AAAI 2026 | 时空数据(Spatial-temporal)论文总结[下](自动驾驶,天气预报,城市科学,POI推荐等)
人工智能·python·深度学习·机器学习·数据挖掘·自动驾驶·智慧城市
Swift社区37 分钟前
LeetCode 455 - 分发饼干
算法·leetcode·职场和发展
郝学胜-神的一滴42 分钟前
人工智能与机器学习:从理论到实践的技术全景
人工智能·python·程序人生·算法·机器学习