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);
    }
}
相关推荐
纠结哥_Shrek39 分钟前
Java 有很多常用的库
java·开发语言
爱是小小的癌1 小时前
Java-数据结构-优先级队列(堆)
java·前端·数据结构
sjsjs111 小时前
【数据结构-字典树】力扣14. 最长公共前缀
数据结构·leetcode
天乐敲代码1 小时前
JAVASE入门十五脚-网络TCP,UDP,,Lambda
java
2501_903238652 小时前
自定义登录页面的Spring Security实践
java·后端·spring·个人开发
JNU freshman2 小时前
力扣第435场周赛讲解
算法·leetcode·蓝桥杯
飞翔的佩奇3 小时前
Java项目: 基于SpringBoot+mybatis+maven+mysql实现的图书管理系统(含源码+数据库+答辩PPT+毕业论文)
java·数据库·spring boot·mysql·spring·毕业设计·图书管理
jerry6095 小时前
注解(Annotation)
java·数据库·sql
Future_yzx5 小时前
Java Web的发展史与SpringMVC入门学习(SpringMVC框架入门案例)
java·前端·学习
pursuit_csdn5 小时前
力扣 347. 前 K 个高频元素
算法·leetcode