Java | Leetcode Java题解之第537题复数乘法

题目:

题解:

java 复制代码
class Solution {
    public String complexNumberMultiply(String num1, String num2) {
        String[] complex1 = num1.split("\\+|i");
        String[] complex2 = num2.split("\\+|i");
        int real1 = Integer.parseInt(complex1[0]);
        int imag1 = Integer.parseInt(complex1[1]);
        int real2 = Integer.parseInt(complex2[0]);
        int imag2 = Integer.parseInt(complex2[1]);
        return String.format("%d+%di", real1 * real2 - imag1 * imag2, real1 * imag2 + imag1 * real2);
    }
}
相关推荐
captain376几秒前
Spring Web MVC(2)
java·前端·spring boot·后端·spring·mvc
代码山河12 分钟前
调试技巧:IDEA Debug模式入门与使用
java·学习·架构·教程·面向对象·项目
文丑颜不良啊24 分钟前
LeetCode851~875题目解析
java·leetcode
技术老孙25 分钟前
给 Agent 装上对话框 —— AgentScope-Java 接入 Spring Boot 与 SSE 流式实战
java·开发语言·spring boot
Navigator_Z38 分钟前
LeetCode //C - 1304. Find N Unique Integers Sum up to Zero
c语言·算法·leetcode
指剑1 小时前
亚麻云之EC2——安全组与密钥对:SSH 端口怎么开才安全,Permission denied (publickey) 和连接超时排查
java·安全·ssh
_Evan_Yao9 小时前
Redis 缓存穿透、击穿、雪崩,一次讲清!
java·spring·mybatis
梓豪csd9 小时前
消息订阅中心:谁该收到哪条通知
java·开发语言·人工智能·低代码·自动化·1024程序员节
秋饼9 小时前
Spring AI 2.1 Message Parts 深度实战:推理签名回放与跨轮记忆持久化的源码级落地
java·ai·技术分享·后端开发
thefool11226610 小时前
TCP 1
java·1024程序员节