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);
    }
}
相关推荐
*.✧屠苏隐遥(ノ◕ヮ◕)ノ*.✧几秒前
JSP, MVC, El, JSTL, MAC
java·开发语言·mvc·mac·jsp
WZ188104638691 分钟前
LeetCode第54题
算法·leetcode
黎雁·泠崖2 分钟前
Java 数据结构与算法:时间空间复杂度 从入门到实战全解
java·开发语言
想不明白的过度思考者6 分钟前
Spring Boot 实战:MyBatis 操作数据库(上)
java·数据库·spring boot·mysql·mybatis
wuqingshun3141598 分钟前
简述双亲委派机制以及其优点
java·开发语言·jvm
丰海洋12 分钟前
Leetcode-hot100-136只出现一次的数字
算法·leetcode·职场和发展
We་ct15 分钟前
LeetCode 124. 二叉树中的最大路径和:刷题解析
前端·数据结构·算法·leetcode·typescript
七夜zippoe24 分钟前
微服务链路追踪实战:SkyWalking vs Zipkin 架构深度解析与性能优化指南
java·开发语言·微服务·springcloud·sleuth·zipkin
米羊12124 分钟前
shiro攻防利用
java·struts·安全
小楼v25 分钟前
AI应用对话生成的安全性优化
java·后端·ai·护轨