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)
相关推荐
智擎GEO5 分钟前
中山GEO优化哪个靠谱
人工智能·python
for_ever_love__8 分钟前
python爬虫: 数据解析
开发语言·爬虫·python·xpath
AR-26710-24 分钟前
机器学习复习收官Day12
人工智能·python·机器学习·scikit-learn
旖旎夜光24 分钟前
LeetCode 525:连续数组(前缀和) —— 题解
数据结构·c++·算法·leetcode·前缀和
xzal1225 分钟前
Python之filter()和map()的区别(仅供学习参考)
笔记·python
随遇而安zx40 分钟前
【地基篇】---JVM 类加载 源码解析(基于 Java 8)
java·jvm·python
2601_962300471 小时前
Python TensorFlow对比PyTorch_Python TensorFlow和PyTorch在机器学习中的差异
pytorch·python·深度学习·机器学习·tensorflow
承渊政道3 小时前
【Python编程—从入门到实践】(Python条件判断完全入门:从布尔表达式到列表中的if实战)
开发语言·python·pycharm·条件判断·布尔表达式
circuitsosk3 小时前
企业知识库 RAG 从 62% 到 91%:分块策略、混合检索与重排序的调优全记录
python·知识库问答·rag·面试项目·ai工程化·混合检索
烂蜻蜓4 小时前
Flask入门教程(二十六):Session API——用户会话状态管理
后端·python·flask