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)
相关推荐
安_7 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
counting money8 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记8 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘9 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
雪碧聊技术9 小时前
安装Python(保姆级教程)
python·版本更新·python下载
++==9 小时前
JSON和Python的 四种核心容器
python·json
203号居民11 小时前
LeetCode hot 100 —41. 缺失的第一个正数
数据结构·算法·leetcode
张龙68712 小时前
uv 全面指南:比 pip 快 100 倍的 Python 包管理器,从安装到团队落地
后端·python
@HNUSTer12 小时前
Python数据可视化科技图表绘制系列教程(八)
python·数据可视化·科技论文·专业制图·科研图表
专注仿真13 小时前
问答大模型技术方案算法实现-熵权法融合算法 + 交叉编码器重排算法
人工智能·python·算法·语言模型·问答大模型关键算法·熵权融合算法·交叉编码器重排算法