Simple Java  Solution with Detail Explanation
IntuitionThe problem requires checking whether a given string of digits can be reduced to two equal numbers by repeatedly summing adjacent digits modulo 10.The
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires checking whether a given string of digits can be reduced to two equal numbers by repeatedly summing adjacent digits modulo 10.

The key observation is that at each step, the array size decreases by 1, and the elements are updated using the sum of adjacent elements modulo 10. The process continues until only two elements remain, and we check if they are equal.

# Approach
<!-- Describe your approach to solving the problem. -->
Convert the input string s into an integer array temp, where each character is converted into its corresponding integer value (s.charAt(i) - '0').
Use a variable p initialized to the length of temp, representing the current size of the array.
While p > 2, iterate through the array and replace each element with the sum of itself and the next element, taken modulo 10.
Decrease p to indicate that the array has shrunk.
When only two elements remain, check if they are equal. If they are, return true; otherwise, return false.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->


The outer loop runs until the array size reduces to 2, which happens in O(n) iterations.
The inner loop processes O(n), O(n-1), ..., O(2) elements over time, totaling O(n²) in the worst case.
Therefore, the overall time complexity is O(n²).


- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
We use an extra integer array temp of size n, leading to a space complexity of O(n).
# Code
```java []
class Solution {
    public boolean hasSameDigits(String s) {
        // Create an array to store integer values of the digits in the string
        int[] temp = new int[s.length()];
        
        // Convert each character in the string to its integer representation
        for (int i = 0; i < temp.length; i++) {
            temp[i] = s.charAt(i) - '0'; // Convert character to integer
        }
        
        // Store the current length of the array
        int p = temp.length;
        
        // Reduce the array size until only two elements remain
        while (p > 2) {
            // Iterate through the array and update each element
            for (int i = 0; i < p - 1; i++) {
                temp[i] = (temp[i] + temp[i + 1]) % 10; // Sum adjacent elements modulo 10
            }
            // Reduce the array size by one
            p--;
        }
        
        // Check if the last two remaining elements are the same
        return temp[0] == temp[1];   
    }
}

```
['Java']