You are given a string s consisting of digits. Perform the following operation repeatedly until the string has exactly two digits:
s, starting from the first digit, calculate a new digit as the sum of the two digits modulo 10.s with the sequence of newly calculated digits, maintaining the order in which they are computed.Return true if the final two digits in s are the same; otherwise, return false.
Example 1:
Input: s = "3902"
Output: true
Explanation:
s = "3902"(s[0] + s[1]) % 10 = (3 + 9) % 10 = 2(s[1] + s[2]) % 10 = (9 + 0) % 10 = 9(s[2] + s[3]) % 10 = (0 + 2) % 10 = 2s becomes "292"(s[0] + s[1]) % 10 = (2 + 9) % 10 = 1(s[1] + s[2]) % 10 = (9 + 2) % 10 = 1s becomes "11""11" are the same, the output is true.Example 2:
Input: s = "34789"
Output: false
Explanation:
s = "34789".s = "7157".s = "862".s = "48".'4' != '8', the output is false.
Constraints:
3 <= s.length <= 105s consists of only digits.Solutions for this problem are being prepared.
Try solving it yourselfPractice Check If Digits Are Equal in String After Operations II with our built-in code editor and test cases.
Practice on FleetCodePractice this problem
Open in Editor