C++, memory beats 100% users, no multiplicative inverse needed, straightforward, simple coding.
Although a lot of people are way smarter than I do, I might as well just post my own implementation here, for the sake of joining the party of thousands of leet
Although a lot of people are way smarter than I do, I might as well just post my own implementation here, for the sake of joining the party of thousands of leetcoders online (-_-). This code's memory usage beats 100% users though.

### Intuition

Quick recap: we can change the base of numbers using simple division.

e.g. 462 (base 10)
= 92 * 5 + 2
= 18 * 5 + 2
= 3 * 5 + 3
= 0 * 5 + 3
= 3322 (base 5)

let string s = "abcdef", each character is a digit.

[a,b,c,d,e,f]
[g,h,i,j,k]
[l,m,n,o]
[p,q,r]
[**A**,**B**]

g=a+b, h=b+c (1 a 2 b 1 c)
l=g+h = (a+b+b+c)+(b+c+c+d) (1 a 3 b 3 c 1 d)

Ha ha, yet another way to represent the mighty Pascal triangle values (-_-)

0C0=1
1C0=1, 1C1=1
2C0=1, 2C1=2, 2C2=1
3C0=1, 3C1=3, 3C2=3, 3C3=1

**A** = a * nC0 +...+ e * nCr

n = string s.length()-2
r = n

s.length() can be 100000. It is not possible to compute, let's say 100000C50000 without causing overflow.

But, with the so-called mighty "Lucas's theorm", nCr mod p, where p is a prime, is equal to:

$${{n}\choose{r}}={{a_{p^{l}}}\choose{b_{p^{l}}}}\times{{c_{p^{l-1}}}\choose{d_{p^{l-1}}}}\times\dots\times{{e_{p^{0}}}\choose{f_{p^{0}}}}$$ 

Where l is the maximum power such that the coefficient of either n or r with base as p is not zero, and a,b,c,d,e,f are all coefficients.

If the coefficients of either n or r or both with base as p for some power l is 0, then $${{a_{p^{l}}}\choose{b_{p^{l}}}}$$ is 0.

For example:

11C6 (mod 5)

11 (base 10) = 21 (base 5)
6 (base 10) = 11 (base 5)

So, 11C6 = 2C1 * 1C1 = 2 (mod 5)

Using such property, we can identify the last digit of a very large nCr (mod p).

Next, consider this table:

|digit|mod 2|mod 5|
|---|---|---|
|0|0|0|
|1|1|1|
|2|0|2|
|3|1|3|
|4|0|4|
|5|1|0|
|6|0|1|
|7|1|2|
|8|0|3|
|9|1|4|

If we want to identify the last digit of the number, we perform a mod 10, and 10 = 2 * 5, and 2 and 5 are primes.

So, by Lucas's theorem, we can determine the nCr (mod 2) and nCr (mod 5) values, and determine the last digit using the table above. 

We cannot directly apply mod 10 to a multiplied value mod by any other values to get the last digit (of course).

Now we can compute  **A**  as follows:

**A** = (a * (last digit of nC0) +...+ e * (last digit of nCr)) mod 10.

Calculate  **B**  as well and check whether  **A** == **B**.

### Approach
Just directly implement the idea in code.
### Complexity
- Time complexity: $$O(N)$$

- Space complexity: $$O(1)$$

Somehow, there are many different implementations and ideas out there. Here's mine: 
### Code
```cpp []
typedef long long int lld;
class Solution {
public:
    int M[10][2]={
        {0,0},{1,1},{2,0},{3,1},{4,0},
        {0,1},{1,0},{2,1},{3,0},{4,1}
    };
    int C[10][10];
    int getOptMod(int n, int r, int p) {
        int res=1;
        while (n&&r) {
            res*=C[n%p][r%p]; res%=p;
            n/=p;r/=p;
        }
        return res;
    }
    int getD(int& f2, int& f5) {
        for (int i=0; i<10; i++) {
            if (M[i][0]==f5&&M[i][1]==f2) {return i;}
        }
        return -1;
    }
    int getVal(string& s, int st, int en) {
        int n=en-st;
        int res=0;
        for (int i=st; i<=en; i++) {
            int d=(int)(s[i]-'0');
            int f2=getOptMod(n,i-st,2);
            int f5=getOptMod(n,i-st,5);
            int mag=getD(f2,f5);
            d*=mag;
            res+=d;
            res%=10;
        }
        return res;
    }
    bool hasSameDigits(string s) {
        int slen=s.length();
        memset(C,0,sizeof(C));
        C[0][0]=1;
        for (int i=1; i<10; i++) {
            C[i][0]=C[i][i]=1;
            for (int j=1; j<i; j++) {
                C[i][j]=C[i-1][j]+C[i-1][j-1];
            }
        }
        return getVal(s,0,slen-2)==getVal(s,1,slen-1);
    }
};
```

Without the Internet, I do not believe that LeetCode would have existed and been used by millions of people.

And solving math and logic puzzles is always a discouraging process for me. Numbers and well-proven formulas are concrete, stubborn, and will never change, and thus a lot of artists always claimed that their creativity supersedes rigid logic. But, when talking about proofing the correctness of formulas, finding new mathematical facts, using math operators to find new truths, or assigning a different meaning to existing facts, all these involves a great deal of creativity and, sometimes, quite counter-intuitive. 

I am always saddened by the fact that I have an ordinary brain and being stuck at performing rudimentary work, and I cannot even excel at my job, which is disappointing. If I ever have gifted genetics to accompany with my strong will and justifiable moral values, I could have done so much more in real life and to experience a multitude of intellectual and spiritual activities beyond my current imagination. I think I always deserve it, and I am stuck now.

I do not believe that having more vacations, socializing more with others, etc., will ever make a slight positive change to my own conditions. All these activities will only make use of basic cognitive and physical abilities that everyone knows. I am not trying to be special. I just want a different life experience that money can never buy.
['C++']