Equal Rational Numbers

Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.

A rational number can be represented using up to three parts: <IntegerPart>, <NonRepeatingPart>, and <RepeatingPart>. The number will be represented in one of the following three ways:

  • <IntegerPart>
  • For example, 12, 0, and 123.
  • <IntegerPart>.<NonRepeatingPart>
  • For example, 0.5, 1., 2.12, and 123.0001.
  • <IntegerPart>.<NonRepeatingPart>(<RepeatingPart>)
  • For example, 0.1(6), 1.(9), and 123.00(1212).

The repeating portion of a decimal expansion is conventionally denoted within a pair of round brackets.

Example 1
Inputs = "0.(52)", t = "0.5(25)"
Outputtrue
Because 0.(52) represents 0.52525252... and 0.5(25) represents 0.52525252525..., the strings represent the same number.
Example 2
Inputs = "0.1666(6)", t = "0.166(66)"
Outputtrue
Both strings represent the same repeating decimal value, 0.166666....

Constraints

  • Each part consists only of digits.
  • The <IntegerPart> does not have leading zeros (except for the zero itself).
  • 1 <= <IntegerPart>.length <= 4
  • 0 <= <NonRepeatingPart>.length <= 4
  • 1 <= <RepeatingPart>.length <= 4

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate