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);
    }
}
相关推荐
Whisper_Sy1 小时前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 网络状态实现
android·java·开发语言·javascript·网络·flutter·php
乂爻yiyao1 小时前
1.1 JVM 内存区域划分
java·jvm
We་ct2 小时前
LeetCode 6. Z 字形变换:两种解法深度解析与优化
前端·算法·leetcode·typescript
没有bug.的程序员2 小时前
Spring Cloud Eureka:注册中心高可用配置与故障转移实战
java·spring·spring cloud·eureka·注册中心
CryptoRzz2 小时前
如何高效接入日本股市实时数据?StockTV API 对接实战指南
java·python·kafka·区块链·状态模式·百度小程序
码农水水3 小时前
中国邮政Java面试被问:容器镜像的多阶段构建和优化
java·linux·开发语言·数据库·mysql·面试·php
若鱼19193 小时前
SpringBoot4.0新特性-BeanRegistrar
java·spring
好好研究3 小时前
SpringBoot - yml配置文件
java·spring boot·spring
学海无涯书山有路4 小时前
Android FragmentContainerView 新手详解(Java 版)
android·java·开发语言
夏鹏今天学习了吗4 小时前
【LeetCode热题100(97/100)】二叉搜索树中第 K 小的元素
算法·leetcode·职场和发展