<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ?LeetCode刷題實(shí)戰(zhàn)537:復(fù)數(shù)乘法

          共 1974字,需瀏覽 4分鐘

           ·

          2022-02-26 12:33

          算法的重要性,我就不多說了吧,想去大廠,就必須要經(jīng)過基礎(chǔ)知識和業(yè)務(wù)邏輯面試+算法面試。所以,為了提高大家的算法能力,這個公眾號后續(xù)每天帶大家做一道算法題,題目就從LeetCode上面選 !

          今天和大家聊的問題叫做?復(fù)數(shù)乘法,我們先來看題面:
          https://leetcode-cn.com/problems/complex-number-multiplication/

          A complex number can be represented as a string on the form "real+imaginaryi" where:


          real is the real part and is an integer in the range [-100, 100].

          imaginary is the imaginary part and is an integer in the range [-100, 100].

          i2 == -1.

          Given two complex numbers num1 and num2 as strings, return a string of the complex number that represents their multiplications.


          復(fù)數(shù) 可以用字符串表示,遵循 "實(shí)部+虛部i" 的形式,并滿足下述條件:
          • 實(shí)部 是一個整數(shù),取值范圍是 [-100, 100]

          • 虛部 也是一個整數(shù),取值范圍是 [-100, 100]

          • i的平分?== -1

          給你兩個字符串表示的復(fù)數(shù) num1 和 num2 ,請你遵循復(fù)數(shù)表示形式,返回表示它們乘積的字符串。

          示例? ? ? ? ? ? ? ? ? ? ? ? ?

          示例 1
          輸入:num1 = "1+1i", num2 = "1+1i"
          輸出:"0+2i"
          解釋:(1?+ i) * (1?+ i) = 1?+ i2 + 2?* i = 2i?,你需要將它轉(zhuǎn)換為 0+2i?的形式。

          示例 2
          輸入:num1 = "1+-1i", num2 = "1+-1i"
          輸出:"0+-2i"
          解釋:(1?- i) * (1?- i) = 1?+ i2 - 2?* i = -2i?,你需要將它轉(zhuǎn)換為 0+-2i?的形式。


          解題


          解題思路:


          public?class?Solution?{

          ????public?String complexNumberMultiply(String a, String b)?{
          ????????String x[] = a.split("\\+|i");
          ????????String y[] = b.split("\\+|i");
          ????????int?a_real = Integer.parseInt(x[0]);
          ????????int?a_img = Integer.parseInt(x[1]);
          ????????int?b_real = Integer.parseInt(y[0]);
          ????????int?b_img = Integer.parseInt(y[1]);
          ????????return?(a_real * b_real - a_img * b_img) + "+"?+ (a_real * b_img + a_img * b_real) + "i";

          ????}
          }



          好了,今天的文章就到這里,如果覺得有所收獲,請順手點(diǎn)個在看或者轉(zhuǎn)發(fā)吧,你們的支持是我最大的動力 。

          上期推文:

          LeetCode1-520題匯總,希望對你有點(diǎn)幫助!
          LeetCode刷題實(shí)戰(zhàn)521:最長特殊序列 Ⅰ
          LeetCode刷題實(shí)戰(zhàn)522:最長特殊序列 II
          LeetCode刷題實(shí)戰(zhàn)523:連續(xù)的子數(shù)組和
          LeetCode刷題實(shí)戰(zhàn)524:通過刪除字母匹配到字典里最長單詞
          LeetCode刷題實(shí)戰(zhàn)525:連續(xù)數(shù)組
          LeetCode刷題實(shí)戰(zhàn)526:優(yōu)美的排列
          LeetCode刷題實(shí)戰(zhàn)527:單詞縮寫
          LeetCode刷題實(shí)戰(zhàn)528:按權(quán)重隨機(jī)選擇
          LeetCode刷題實(shí)戰(zhàn)529:掃雷游戲
          LeetCode刷題實(shí)戰(zhàn)530:二叉搜索樹的最小絕對差
          LeetCode刷題實(shí)戰(zhàn)531:孤獨(dú)像素 I
          LeetCode刷題實(shí)戰(zhàn)532:數(shù)組中的K-diff數(shù)對
          LeetCode刷題實(shí)戰(zhàn)533:孤獨(dú)像素 II
          LeetCode刷題實(shí)戰(zhàn)534:游戲玩法分析 III
          LeetCode刷題實(shí)戰(zhàn)535:TinyURL 的加密與解密
          LeetCode刷題實(shí)戰(zhàn)536:從字符串生成二叉樹

          瀏覽 35
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲蜜桃一区二区 | 影音先锋男人资源av | 日韩一区二区三区四区 | 特级茜茜人体444WWw高清大胆 | 日本免费一级视频 |