Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    972 - Equal Rational Numbers\.

    Hard

    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 a <RepeatingPart>. The number will be represented in one of the following three ways:

    • <IntegerPart>

    • <code><IntegerPart><.><NonRepeatingPart></code>

    • <code><IntegerPart><.><NonRepeatingPart><(><RepeatingPart><)></code>

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

    • 1/6 = 0.16666666... = 0.1(6) = 0.1666(6) = 0.166(66).

    Example 1:

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

    Output: true

    Explanation: Because "0.(52)" represents 0.52525252..., and "0.5(25)" represents 0.52525252525..... , the strings represent the same number.

    Example 2:

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

    Output: true

    Example 3:

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

    Output: true

    Explanation: "0.9(9)" represents 0.999999999... repeated forever, which equals 1. [See this link for an explanation.](https://en.wikipedia.org/wiki/0.999...) "1." represents the number 1, which is formed correctly: (IntegerPart) = "1" and (NonRepeatingPart) = "".

    Constraints:

    • Each part consists only of digits.

    • The &lt;IntegerPart&gt; does not have leading zeros (except for the zero itself).

    • 1 &lt;= &lt;IntegerPart&gt;.length &lt;= 4

    • 0 &lt;= &lt;NonRepeatingPart&gt;.length &lt;= 4

    • 1 &lt;= &lt;RepeatingPart&gt;.length &lt;= 4

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean isRationalEqual(String s, String t)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait