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);
    }
}
相关推荐
张柏慈11 小时前
Java性能优化:实战技巧与案例解析
java
天“码”行空11 小时前
简化Lambda——方法引用
java·开发语言
让我上个超影吧11 小时前
【力扣26&80】删除有序数组中的重复项
算法·leetcode
带刺的坐椅12 小时前
MCP 进化:让静态 Tool 进化为具备“上下文感知”的远程 Skills
java·ai·llm·agent·solon·mcp·tool-call·skills
java1234_小锋12 小时前
Java线程之间是如何通信的?
java·开发语言
张张努力变强12 小时前
C++ Date日期类的设计与实现全解析
java·开发语言·c++·算法
while(1){yan}13 小时前
Spring事务
java·数据库·spring boot·后端·java-ee·mybatis
漫随流水13 小时前
leetcode回溯算法(78.子集)
数据结构·算法·leetcode·回溯算法
毕设源码-赖学姐13 小时前
【开题答辩全过程】以 高校社团管理平台为例,包含答辩的问题和答案
java
We་ct13 小时前
LeetCode 151. 反转字符串中的单词:两种解法深度剖析
前端·算法·leetcode·typescript