334. Add Two Large Numbers Represented as Strings
Add Two Large Numbers Represented as Strings
Given two non-negative integers represented as strings, return their sum as a string.
The numbers may be too large for standard numeric data types. You must perform the addition without using any big-integer library or converting the complete strings into numeric values.

Method Signature

String addLargeNumbers(String firstNumber, String secondNumber)
  • firstNumber is the string representation of the first non-negative integer.
  • secondNumber is the string representation of the second non-negative integer.
  • Returns the sum of firstNumber and secondNumber as a string.

Rules

  • Each input contains only digits from '0' to '9'.
  • Inputs do not contain leading zeros unless the entire number is "0".
  • The returned string must not contain unnecessary leading zeros.
  • Standard big-integer libraries must not be used.
  • The complete input strings must not be converted directly into built-in numeric types.

Constraints

  • 1 ≤ firstNumber.length() ≤ 100,000
  • 1 ≤ secondNumber.length() ≤ 100,000
  • firstNumber and secondNumber contain only decimal digits.

Examples

Example 1

addLargeNumbers(firstNumber = "875", secondNumber = "968")
Output: "1843"

Example 2

addLargeNumbers(firstNumber = "99999999999999999999", secondNumber = "7")
Output: "100000000000000000006"

Example 3

addLargeNumbers(firstNumber = "0", secondNumber = "45000000000000000000")
Output: "45000000000000000000"


Please use Laptop/Desktop or any other large screen to add/edit code.