C++ with explanation, O(n), 14ms
First, check the sequence of L and R in start and end is the same;\nSecond, index of L in start should be >= index of corresponding L in end, while index of R <
First, check the sequence of L and R in start and end is the same;\nSecond, index of L in start should be >= index of corresponding L in end, while index of R <= corresponding index.\n```\nclass Solution {\npublic:\n    bool canTransform(string start, string end) {\n        int n = start.size();\n        string s1, s2;\n        for (int i = 0; i < n; ++i) \n            if (start[i] != 'X') s1 += start[i];\n        for (int i = 0; i < n; ++i) \n            if (end[i] != 'X') s2 += end[i];\n        if (s1 != s2) return false;\n        for (int i = 0, j = 0; i < n && j < n;) {\n            if (start[i] == 'X') \n               i++;\n            else if (end[j] == 'X') \n               j++;\n            else {\n                if ((start[i] == 'L' && i < j) || (start[i] == 'R' && i > j)) return false;\n                i++;\n                j++;\n            }\n        }\n        return true;\n    }\n};\n```
[]