Skip to content

Practice Equal Rational Numbers

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#972
LeetCode Problem

Equal Rational Numbers

Problem Statement

Given s and t representing nonnegative rational numbers, return whether their values are equal. A representation may be an integer alone, an integer followed by a decimal point and a possibly empty nonrepeating part, or that decimal form followed by a nonempty repeating part in parentheses. The parenthesized digits repeat forever. Compare the represented numbers rather than their spellings; repeating 9s may represent a terminating value.

Source: Equal Rational Numbers on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "0.(52)", t = "0.5(25)"
Output
true

# Example 2

Input
s = "0.1666(6)", t = "0.166(66)"
Output
true

# Example 3

Input
s = "0.9(9)", t = "1."
Output
true

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

Related LeetCode Problems

Practice more problems similar to Equal Rational Numbers.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.