Skip to main content

Multiply Strings

Multiply two non-negative integers represented as strings Return the product as a string Do not convert the strings to integers directly Example: "2" * "3" = "6" Example: "123" * "456" = "56088"

Given two non-empty strings num1 and num2 representing non-negative decimal integers, return their product as a decimal string. Each input contains only digits 0 through 9 and has no leading zeros unless it is "0". Return "0" for a zero product and otherwise omit leading zeros. Do not convert either entire input string directly to an integer.

Math & GeometryString

Examples

You write

multiply(num1: str, num2: str)

  1. Example 1

    Input
    num1 = "2", num2 = "3"
    returns
    "6"
  2. Example 2

    Input
    num1 = "123", num2 = "456"
    returns
    "56088"

The pattern behind it

Strings

I reach for it when

  • The input is text and the answer is a count, a substring or a new string.
  • You need to compare, reverse or rebuild characters.

Say this before you type. Say which array pattern the string is hiding before you touch a character.

All 51 Strings problems

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Multiply Stringsmedium