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)
相关推荐
m0_716667072 分钟前
NumPy入门:高性能科学计算的基础
jvm·数据库·python
带娃的IT创业者30 分钟前
Weclaw 请求路由实战:一个 request_id 如何在 800 个并发连接中精准找到目标浏览器?
python·websocket·fastapi·架构设计·实时通信·openclaw·weclaw
2401_844221321 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
样例过了就是过了2 小时前
LeetCode热题100 N 皇后
数据结构·c++·算法·leetcode·dfs·深度优先遍历
白雨青2 小时前
国信 iQuant 自动国债逆回购实战:Python 自动化闲钱理财
python·量化策略·量化交易·国债逆回购
qq_404265833 小时前
用Python批量处理Excel和CSV文件
jvm·数据库·python
才兄说3 小时前
机器人租售效果好吗?任务前对齐需求
python
喵手4 小时前
Python 爬虫实战:构建开源主题模板版本库
爬虫·python·数据采集·爬虫实战·零基础python爬虫教学·开源主题·采集开源主题模版本库
qq_418101774 小时前
使用Scikit-learn进行机器学习模型评估
jvm·数据库·python
样例过了就是过了4 小时前
LeetCode热题100 分割回文串
数据结构·c++·算法·leetcode·深度优先·dfs