[C++] one pass - time:O(n) space:O(1) (with explanation)
Here I translate \'X\' to \'.\' for understanding more easily.\n\n\nstart = "R..LR.R.L"\nend   = ".RL..RRL."\n\nFrom the above example, we can find some rules f
Here I translate \'X\' to \'.\' for understanding more easily.\n\n```\nstart = "R..LR.R.L"\nend   = ".RL..RRL."\n```\nFrom the above example, we can find some rules for \'L\' and \'R\':\n\n**1. "*XL*" to "*LX*": L only go left\n2. "*RX*" to "*XR*": R only go right\n3. L and R cannot change their order**\n\nFor example, if we have "XXXXXXXL" and finally we may get the result "LXXXXXXX".\n###### -----------------------------------------------------------------\nWe only need to check the "L" and "R" position in two string.\nUsing two pointer `i` and `j` to keep comparing:\n1. skip \'X\', make sure `start[i]` and `end[j]` is the same \n2. \'R\' position in `start` is smaller than `end`\n3. \'L\' position in `start` is larger than `end`\n\n```\nclass Solution {\npublic:\n    bool canTransform(string start, string end) {\n        \n        int i=0, j=0;\n        while(i<start.size() && j<end.size()) {\n            \n            while(start[i]==\'X\') i++;\n            while(end[j]==\'X\') j++;\n            \n            if(start[i]!=end[j]) return false;\n            if(start[i]==\'R\' && i>j) return false;\n            if(start[i]==\'L\' && i<j) return false;\n            i++; j++;\n        }\n        while(i<start.size() && start[i]==\'X\') i++;\n        while(j<end.size() && end[j]==\'X\') j++;\n        return i==j;\n    }\n};\n```\n
['C']