Recursive ✅ - Beats 100% - Python/Java/C++
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python []
class Solution:
    def hasSameDigits(self, s: str) -> bool:
        ans = [int(i) for i in s]
        while len(ans) > 2:
            ans = [(ans[i] + ans[i + 1]) % 10 for i in range(len(ans) - 1)]
        return ans[0] == ans[1]
```
```java []
class Solution {
    public boolean hasSameDigits(String s) {
        int[] ans = new int[s.length()];
        for (int i = 0; i < s.length(); i++) {
            ans[i] = s.charAt(i) - '0';
        }
        while (ans.length > 2) {
            int[] temp = new int[ans.length - 1];
            for (int i = 0; i < ans.length - 1; i++) {
                temp[i] = (ans[i] + ans[i + 1]) % 10;
            }
            ans = temp;
        }
        return ans[0] == ans[1];
    }
}
```
```cpp []
class Solution {
public:
    bool hasSameDigits(string s) {
        vector<int> ans;
        for (char c : s) {
            ans.push_back(c - '0');
        }
        while (ans.size() > 2) {
            vector<int> temp;
            for (size_t i = 0; i < ans.size() - 1; i++) {
                temp.push_back((ans[i] + ans[i + 1]) % 10);
            }
            ans = temp;
        }
        return ans[0] == ans[1];
    }
};
```
['C++', 'Java', 'Python3']