Simple and Intuitive Python Solution – No Need for Lucas’ Theorem
ApproachIf the input string is "abcde", the the calculation chain:a, b, c, d, e
(a + b), (b + c), (c + d), (d + e)
(a + 2b + c), (b + 2c + d), (c + 2d + e)
(a +
# Approach
<!-- Describe your approach to solving the problem. -->
If the input string is "abcde", the the calculation chain:

a, b, c, d, e
(a + b), (b + c), (c + d), (d + e)
(a + 2b + c), (b + 2c + d), (c + 2d + e)
(a + 3b + 3c + d), (b + 3c + 3d + e)

Each step has binomial coefficients. If input length is n (eg. 5 for 'abcde'), then we'll need the binomial coefficients for (1 + x)^(n-2) (eg. (1 + x)^3 which is 1, 3, 3, 1).  


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

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

# Code
```python3 []
class Solution:
    def hasSameDigits(self, s: str) -> bool:

        s = [int(c) for c in s]

        def generateBinomials(n):
            """
            generate binomial coefficients
            if n = 3, res = [1, 3, 3, 1]
            if n = 4, res = [1, 4, 6, 4, 1]
            """
            res = [1] * (n + 1)
            # calculate only half of the binomial coefficients
            for i in range(1, n // 2 + 1):
                res[i] = res[i - 1] * (n - i + 1) // i
            # use only last digit
            res = [r % 10 for r in res]
            # copy other half
            for i in range(n, n // 2, -1):
                res[i] = res[n - i]  
            return res
        
        # get the binomial coefficients
        binomials = generateBinomials(len(s) - 2)
        
        # get the last two results
        x = sum(i * j % 10 for i, j in zip(binomials, s[:-1]))
        y = sum(i * j % 10 for i, j in zip(binomials, s[1:]))

        return x % 10 == y % 10

```
['Python3']