✅ Check If Digits Are Equal || C++ ⚡ JAVA || Beginner Friendly 🔥🔥
IntuitionThe problem involves iteratively transforming a string of digits by replacing each pair of adjacent digits with their sum modulo 10. This process conti
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem involves iteratively transforming a string of digits by replacing each pair of adjacent digits with their sum modulo 10. This process continues until the string is reduced to two characters, at which point we check if they are the same. The intuition is to simulate this transformation step by step using a loop.

# Approach
<!-- Describe your approach to solving the problem. -->
1. Start with the given string s.
2. While the length of s is greater than 2:
- Create a new string by iterating through adjacent character pairs.
- Compute their sum modulo 10 and store the result in a new string.
- Replace s with the newly generated string.
3. Once s is reduced to two characters, check if they are equal.
4. Return true if they match, otherwise return false.

# Complexity
**- Time complexity:**
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Each transformation reduces the string length approximately by half, leading to a logarithmic behavior.
- However, since we process all characters in each iteration, the worst case is O(n²).


**- Space complexity:**
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
- We store intermediate strings in each step, leading to O(n) auxiliary space.

# Code
```cpp []
class Solution {
public:
    bool hasSameDigits(string s) {
           while (s.length() > 2) {
            string s1 = "";
            for (size_t i = 0; i < s.length() - 1; i++) {
                int a = (s[i] + s[i + 1] ) % 10;
                s1 += a ;
            }
            s =s1;
        }
        return s[0] == s[1];
    }
};
```
```java []
 boolean hasSameDigits(String s) {
        while (s.length() > 2) {
            StringBuilder s1 = new StringBuilder();
            for (int i = 0; i < s.length() - 1; i++) {
                int a = (s.charAt(i) + s.charAt(i + 1)) % 10;
                s1.append(a);
            }
            s = s1.toString();
        }
        return s.charAt(0) == s.charAt(1);
    }

['String', 'C++', 'Java']