2 pointers nested loop||beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n2 pointers again, move i, j pointers for s, t to see when they are both not \'\'.\nC++,
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n2 pointers again, move `i, j` pointers for `s, t` to see when they are both not \'_\'.\nC++, Python, C are made.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n[Please turn English subtitles if necessary]\n[https://youtu.be/JAw_prYl0ps?si=Iyikw49MY-BJz2Nz](https://youtu.be/JAw_prYl0ps?si=Iyikw49MY-BJz2Nz)\n1. let `n` be the length for `s` &`\'t\'`\n2. Move `i, j` both for `s, t` by using for loop with increment `i++, j++`\n3. In the inner loop move i until s[i]!=\'_\'\n4. In the inner loop move j until t[j]!=\'_\'\n5. If `s[i]!=t[j]` return false\n6. If `s[i]==t[j]=\'L\'` and `i<j` return false\n7. If `s[i]==t[j]=\'R\'` and `i>j` return false\n8. end the nested loop, all conditions for `s[i]==t[j]` are passed, return true.\n# Why C, C++  s[n], t[n] cause no problem?\nFor C-string it is clear that `s[n]==\'\\0\'` which is the string terminal char. C++ string is similar. When other language is used, it needs to be modified.\n\nThe trick adding an extra char is used for the 2-pointer questions\n- [2825. Make String a Subsequence Using Cyclic Increments](https://leetcode.com/problems/make-string-a-subsequence-using-cyclic-increments/solutions/6110652/1-pass-2-pointers-beats-100/)\n- [2109. Adding Spaces to a String](https://leetcode.com/problems/adding-spaces-to-a-string/solutions/6106375/2-pointers-4ms-beats-100/)\n# Real RUN for testcase\nLet\'s consider some testcase, say `"_L__R__R_"\n"L______RR"`\nThe process is run by the submtted Python code with adding some outputs:\n```\ns[1]=L t[0]=L\ns[4]=R t[7]=R\ns[7]=R t[8]=R\ns[9]=@ t[9]=@\n=>True\n```\nOher testcase is `"_LL___R__R_"\n"L___L____RR"` with process\n```\ns[1]=L t[0]=L\ns[2]=L t[4]=L\n=>False\n```\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$O(n)$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$O(1)$ for C & C++\n# Code||C++ 0ms beats 100%\n```cpp []\nclass Solution {\npublic:\n    static bool canChange(string& s, string& t) {\n        const int n=s.size();\n        for(int i=0, j=0; i<n || j<n; i++, j++){\n            while(i<n && s[i]==\'_\') i++;\n            while(j<n && t[j]==\'_\') j++;\n        //    cout<<i<<", "<<j<<endl;\n            char c=s[i];\n            if (c !=t[j]) return 0;\n            if (c ==\'L\' && i<j) return 0;\n            if (c ==\'R\' && i>j) return 0;\n        }\n        return 1;\n    }\n};\n\n\n\nauto init = []() {\n    ios::sync_with_stdio(false);\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return \'c\';\n}();\n```\n```Python []\nclass Solution:\n    def canChange(self, s: str, t: str) -> bool:\n        n=len(s)\n        s+=\'@\'\n        t+=\'@\'\n        i, j=0, 0\n        while i<n or j<n:\n            while i<n and s[i]==\'_\': i+=1\n            while j<n and t[j]==\'_\': j+=1\n            c=s[i]\n            if c!=t[j]: return False\n            if c==\'L\' and i<j: return False\n            if c==\'R\' and i>j: return False\n            i+=1\n            j+=1\n        return True\n        \n        \n```\n```C []\n#pragma GCC optimize("O3", "unroll-loops")\nbool canChange(char* s, char* t) {\n    const int n=strlen(s);\n    for (register int i=0, j=0; i<n  || j<n ; i++, j++){\n        while(i<n && s[i]==\'_\') i++;\n        while(j<n && t[j]==\'_\') j++;\n        char c=s[i];\n        if (c!=t[j]) return 0;\n        if (c==\'L\' && i<j) return 0;\n        if (c==\'R\' && i>j) return 0;\n    }\n    return 1;\n}\n```
['Two Pointers', 'String', 'C', 'C++', 'Python3']