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)
相关推荐
曲幽11 分钟前
FastAPI多进程部署:定时任务重复执行?手把手教你用锁搞定
redis·python·fastapi·web·lock·works
漫随流水42 分钟前
leetcode回溯算法(78.子集)
数据结构·算法·leetcode·回溯算法
森屿~~1 小时前
AI 手势识别系统:踩坑与实现全记录 (PyTorch + MediaPipe)
人工智能·pytorch·python
We་ct1 小时前
LeetCode 151. 反转字符串中的单词:两种解法深度剖析
前端·算法·leetcode·typescript
忧郁的橙子.1 小时前
26期_01_Pyhton文件的操作
开发语言·python
wen__xvn2 小时前
代码随想录算法训练营DAY25第七章 回溯算法 part04
算法·leetcode·深度优先
小CC吃豆子2 小时前
Python爬虫
开发语言·python
June bug3 小时前
(#字符串处理)字符串中第一个不重复的字母
python·leetcode·面试·职场和发展·跳槽
lixzest3 小时前
PyTorch基础知识简述
人工智能·pytorch·python
飞Link3 小时前
深度学习里程碑:ResNet(残差网络)从理论到实战全解析
人工智能·python·深度学习