My Solution
```
/**
 * Time Complexity: O(n * log(n))
 * Space Complexity: O(1)
 * where `n` is the length of the string `s`
 */
class Solution {
 private:
  static constexpr int mod = 10;
  static constexpr int prime_factor2 = 2;
  static constexpr int prime_factor5 = 5;

 public:
  bool hasSameDigits(const string &s) {
    constexpr int max_mod = 5;
    constexpr char zero = '0';
    const int n = static_cast<int>(s.size());
    vector<vector<int>> comb(max_mod, vector<int>(max_mod, 0));
    for (int i = 0; i < max_mod; ++i) {
      for (int j = 0; j < i + 1; ++j) {
        if (j == 0) {
          comb[i][j] = 1;
        } else {
          comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
        }
      }
    }

    int a1 = 0;
    int a2 = 0;
    for (int i = 0; i < n - 1; ++i) {
      const int c = crt(n - 2, i, comb);
      a1 = (a1 + c * (s[i] - zero)) % mod;
      a2 = (a2 + c * (s[i + 1] - zero)) % mod;
    }
    return a1 == a2;
  }

 private:
  int lucas(const int n, const int m, const int p, const vector<vector<int>> &comb) {
    if (m == 0) {
      return 1;
    }
    return (lucas(n / p, m / p, p, comb) * comb[n % p][m % p]) % p;
  }

  int crt(const int n, const int m, const vector<vector<int>> &comb) {
    return (prime_factor2 * lucas(n, m, prime_factor5, comb) +
            prime_factor5 * lucas(n, m, prime_factor2, comb)) % mod;
  }
};
```
['C++']