【Python】 3.17

Trp_Cys Trp_Cys 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

题目: 509. 斐波那契数 - 力扣(Leetcode)

class Solution:
    def fib(self, n: int) -> int:
        dp = [1] * (n + 1)
        dp[0] = 0
        for i in range (2, n + 1):
            dp[i] = dp[i - 1] + dp[i - 2]
        return dp[n]

 

题目:  537. 复数乘法 - 力扣(Leetcode)

class Solution:
    def complexNumberMultiply(self, num1: str, num2: str) -> str:
        real1, imag1 = map(int,num1[:-1].split('+'))
        real2, imag2 = map(int,num2[:-1].split('+'))
        real3 = real1 * real2 - imag1 * imag2
        imag3 = real1 * imag2 + real2 * imag1
        return ("{}+{}i").format(real3, imag3)

 

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部