[c++, 10 lines, O(n)] detailed explaination, easy to understand!
The basic idea is to count the number of R in start string, and the number of L in end string. \nThe reason is that when we meet a \'R\' in the end string, we h
The basic idea is to count the number of R in start string, and the number of L in end string. \nThe reason is that when we meet a \'R\' in the end string, we hope there is a \'R\' in the start string before. This is why we need to count the number of R in the start string.\nAnd when we meet a \'L\' in the start string, we hope we have meet a \'L\' in the end string before.\nIf we didn\'t meet what we need before, return false, that is  (cnt_r < 0 || cnt_l < 0).\nIf we meet both \'L\' and \'R\', return false, because we cannot let a \'L\' or \'R\' go across each other, and that is (cnt_r > 0 && cnt_l > 0)\n\nIn the end, we hope all R and L have been used, that is return cnt_r == 0 && cnt_l == 0\n```\n    bool canTransform(string start, string end) {\n        if(start.length() != end.length()) return false;\n        int cnt_r = 0, cnt_l = 0;\n        for(int i = 0, j = 0; i < start.size(), j < end.size(); i++, j++) {\n            cnt_r += start[i] == \'R\' ? 1 : 0;\n            cnt_l += end[j] == \'L\' ? 1 : 0;\n            if(end[j] == \'R\' && cnt_l == 0) cnt_r --;\n            if(start[i] == \'L\' && cnt_r == 0) cnt_l --;\n            if(cnt_r < 0 || cnt_l < 0 || (cnt_r > 0 && cnt_l > 0)) return false;\n        }\n        return cnt_r == 0 && cnt_l == 0;\n    }\n```
[]