Easy to understand 
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
```cpp []
class Solution {
public:

   vector<int> get_base5_digits(int n) {
    vector<int> res;
    if (n == 0) {
        res.push_back(0);
        return res;
    }
    while (n > 0) {
        res.push_back(n % 5);
        n /= 5;
    }
    return res;
}
    bool hasSameDigits(string s) {
         int n = s.size();
    if (n == 2) {
        return s[0] == s[1];
    }
    int m = n - 2;

    int mod5_table[5][5] = {
        {1, 0, 0, 0, 0}, // n=0
        {1, 1, 0, 0, 0}, // n=1
        {1, 2, 1, 0, 0}, // n=2
        {1, 3, 3, 1, 0}, // n=3
        {1, 4, 1, 4, 1}  // n=4
    };

    int mod10_table[2][5] = {
        {0, 6, 2, 8, 4}, // a=0
        {5, 1, 7, 3, 9}  // a=1
    };

    vector<int> m_digits = get_base5_digits(m);

    vector<int> coefficients(m + 1);

    for (int j = 0; j <= m; ++j) {
        int mod2 = ((j & m) == j) ? 1 : 0;

        vector<int> j_digits = get_base5_digits(j);
        if (j_digits.size() > m_digits.size()) {
            coefficients[j] = mod10_table[mod2][0];
            continue;
        }

        int mod5 = 1;
        for (int d = 0; d < m_digits.size(); ++d) {
            int jd = (d < j_digits.size()) ? j_digits[d] : 0;
            if (jd > m_digits[d]) {
                mod5 = 0;
                break;
            }
            mod5 = (mod5 * mod5_table[m_digits[d]][jd]) % 5;
        }

        int b = mod5 % 5;
        coefficients[j] = mod10_table[mod2][b];
    }

    int sum1 = 0, sum2 = 0;
    for (int i = 0; i <= m; ++i) {
        sum1 = (sum1 + (s[i] - '0') * coefficients[i]) % 10;
    }
    for (int i = 0; i <= m; ++i) {
        sum2 = (sum2 + (s[i + 1] - '0') * coefficients[i]) % 10;
    }

    return sum1 == sum2;
    }
};
```
['C++']