Check If Digits Are Equal in String After Operations II
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
```java []
class Solution {
    public boolean hasSameDigits(String s) {
        int n = s.length();
        if (n < 3) return false;  
        
        int N = n - 2;
        int n0 = 0, n1 = 0;
        
        for (int j = 0; j <= N; j++) {
            int c = bMod10(N, j);
            n0 = (n0 + c * (s.charAt(j) - '0')) % 10;
            n1 = (n1 + c * (s.charAt(j + 1) - '0')) % 10;
        }
        
        return n0 == n1;
    }
    
    private int bMod10(int n, int k) {
        if (k < 0 || k > n) return 0;
        if (k == 0 || k == n) return 1;
        
       
        k = Math.min(k, n - k);
        
       
        int r2 = bMod2(n, k);
        int r5 = bMod5(n, k);
        
      
        for (int x = 0; x < 10; x++) {
            if (x % 2 == r2 && x % 5 == r5) return x;
        }
        return 0;  
    }
    
    private int bMod2(int n, int k) {
       
        return ((n & k) == k) ? 1 : 0;
    }
    
    private int bMod5(int n, int k) {
        
        int[][] gird = {
            {1, 0, 0, 0, 0},  
            {1, 1, 0, 0, 0},  
            {1, 2, 1, 0, 0},  
            {1, 3, 3, 1, 0},  
            {1, 4, 1, 4, 1}   
        };
        
        int ans = 1;
        while (n > 0 || k > 0) {
            int l = n % 5;
            int m = k % 5;
            if (m > l) return 0;
            ans = (ans * gird[l][m]) % 5;
            n /= 5;
            k /= 5;
        }
        return ans;
    }
}
```
['Java']