Class Solution
-
- All Implemented Interfaces:
public final class Solution3463 - Check If Digits Are Equal in String After Operations II.
Hard
You are given a string
sconsisting of digits. Perform the following operation repeatedly until the string has exactly two digits:For each pair of consecutive digits in
s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.Replace
swith the sequence of newly calculated digits, maintaining the order in which they are computed.
Return
trueif the final two digits insare the same; otherwise, returnfalse.Example 1:
Input: s = "3902"
Output: true
Explanation:
Initially,
s = "3902"First operation:
Second operation:
Since the digits in
"11"are the same, the output istrue.
Example 2:
Input: s = "34789"
Output: false
Explanation:
Initially,
s = "34789".After the first operation,
s = "7157".After the second operation,
s = "862".After the third operation,
s = "48".Since
'4' != '8', the output isfalse.
Constraints:
<code>3 <= s.length <= 10<sup>5</sup></code>
sconsists of only digits.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanhasSameDigits(String s)-
-
Method Detail
-
hasSameDigits
final Boolean hasSameDigits(String s)
-
-
-
-