Java Easy Understanding with explanation
(i) First, \'L\' cannot swap to left of \'R\', and \'R\' cannot swap to right of \'L\'. So we remove all \'X\' in both start and end to find if all \'L\' and \'
(i) First, \'L\' cannot swap to left of \'R\', and \'R\' cannot swap to right of \'L\'. So we remove all \'X\' in both `start` and `end` to find if all \'L\' and \'R\' in the same order. If not, return false.\n\n(ii) Second, let\'s look at this pair:\n\tstart: "LXX"\n\tend:    "XXL"\n\tAfter removing all \'X\', this pair can pass the first condition. But `start` can\'t transfer to `end`. The problem is the positon of \'L\' in `start` is more left than the \'L\' in `end` (\'L\' can only go to left side, can\'t go right). So we go through two strings(from `0` to `start.length()`), to make sure every \'L\' comes earlier in `end`. \n\tFor \'R\', make sure every \'R\' comes earlier in `start`. \n```\npublic boolean canTransform(String start, String end) {\n\t// First, remove all \'X\', and compare if they equal.\n\tStringBuffer s = new StringBuffer();\n\tStringBuffer e = new StringBuffer();\n\tfor (char c : start.toCharArray()) {\n\t\tif (c != \'X\') {\n\t\t\ts.append(c);\n\t\t}\n\t}\n\tfor (char c : end.toCharArray()) {\n\t\tif (c != \'X\') {\n\t\t\te.append(c);\n\t\t}\n\t}\n\tif (!s.toString().equals(e.toString()))\n\t\treturn false;\n\t// check R\n\t// form i to start.length(), \n\t// if R found in start count++, \n\t// if R found in end count--, \n\t// if count comes to negative, that means \'R\' is in more left position in end, so \'R\' can\'t move from start to end.\n\tint count = 0;\n\tfor (int i = 0; i < start.length(); i++) {\n\t\tif (start.charAt(i) == \'R\') {\n\t\t\tcount++;\n\t\t}\n\t\telse if (end.charAt(i) == \'R\') {\n\t\t\tcount--;\n\t\t}\n\t\tif (count < 0) {\n\t\t\treturn false;\n\t\t}\n\t}\n\t// check L\n\t// same with checking \'R\', only difference is: \n\t// to ensure every \'L\' comes first in end.\n\tcount = 0;\n\tfor (int i = 0; i < start.length(); i++) {\n\t\tif (end.charAt(i) == \'L\') {\n\t\t\tcount++;\n\t\t}\n\t\telse if (start.charAt(i) == \'L\') {\n\t\t\tcount--;\n\t\t}\n\t\tif (count < 0) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n```\n\nIt is easy to understand, if it helps, upvote please! \n^_^\n
['Java']