0ms 100% infinite harmony check
ApproachThe core idea revolves around iterative digit reduction. We start with a string of digits and repeatedly transform it by processing adjacent pairs.The c
**Approach**

The core idea revolves around iterative digit reduction. We start with a string of digits and repeatedly transform it by processing adjacent pairs.

The code enters an infinite for (;;) loop, designed for repeated transformation until a termination condition is met:
- Adjacent Digit Summation
- Termination and Harmony Check
- String update/Swap

**Complexity**
In each iteration, the inner loop scales with the current string length, which decreases by approximately one in each outer iteration. Consequently, the time complexity is O(n<sup>2</sup>) where n is the initial string length.
The space usage is  dominated by the temporary string next. Its size is, at most, the size of the input string in each iteration. Therefore, the space complexity remains O(n).


# Code
```cpp []
class Solution {
public:
    bool hasSameDigits(string& s) {
        constexpr int TWO_ASCII_ZERO  = 2 * '0';        

        string next;
        next.reserve(s.size());
        
        for (;;) {
            next.clear();
            for (int i = 1; i < s.size(); ++i) {
                const int sum = ( (s[i - 1] + s[i] - TWO_ASCII_ZERO )  ) ;
                const int char_sum =  ((sum <= 9) ? sum : (sum - 10)) + '0';
                next.push_back(char_sum);
            }
     
            if (next.size() == 2) {
                return next.front() == next.back();
            }
            swap(next, s);
        }
        return false;
        
        
    }
};
```
['C++']