力扣编程从0-1

第一题

python 复制代码
class Solution:
    def mergeAlternately(self, word1: str, word2: str) -> str:
        #计算两个字符串长度,从i = 0开始遍历,每次循环:
        #如果i小于word1的长度,把word1[i]加到答案末尾
        #如果i小于word2的长度,把word2[i]加到答案末尾
        #循环直到i达到word1的长度和word2长度的最大值。
        ans = []
        i,n,m = 0,len(word1),len(word2)
        while i < n or i < m:
            if i<n:
                ans.append(word1[i])
            if i < m:
                ans.append(word2[i])
            i += 1
        return "".join(ans)
      # 时间复杂度:O(n+m),其中 n 是 word1的长度,m 是 word2的长度。
       #空间复杂度:O(n+m) 或 O(1)。C++ 不计入返回值的空间。
相关推荐
JieE2124 小时前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断
javascript·算法
金銀銅鐵9 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup1114 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0016 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵18 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf18 小时前
Agent 流程编排
后端·python·agent
copyer_xyf19 小时前
Agent RAG
后端·python·agent
copyer_xyf19 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf19 小时前
Agent 记忆管理
后端·python·agent