150強訪談簡單

字串相乘

“乘法字串”問題的詳細指南和 Python 實作。

問題陳述

簡單

給定兩個非負整數 num1 和 num2(表示為字串),傳回 num1 和 num2(也表示為字串)的乘積。

注意:您不得使用任何內建 BigInteger 函式庫或直接將輸入轉換為整數。

實作函數 multiply(num1: str, num2: str) -> str

約束條件
  • 1 <= num1.length, num2.length <= 200
  • num1 and num2 consist of digits only
  • Both num1 and num2 do not contain any leading zero, except the number 0 itself

範例

Example 1
Input
"2", "3"
Output
"6"
Explanation

2 * 3 = 6.

Example 2
Input
"123", "456"
Output
"56088"
Explanation

123 * 456 = 56088.

Need a Hint?
考慮使用數學和幾何特定的資料結構,例如集合或堆疊。
Edge Cases to Watch
  • 空輸入結構
  • 單元素輸入
  • 大數值範圍

準備好解決了嗎?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

在編輯器中開啟
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推薦的 Python 資源

透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。