Java | One Pass | All Test Cases Passed
There are three restrictions:\n1. the number and sequence of L and R should be equal\n2. L can not be moved to the right\n3. R can not be moved to the left\n\nT
There are three restrictions:\n1. the number and sequence of L and R should be equal\n2. L can not be moved to the right\n3. R can not be moved to the left\n\nThere are several new cases, say "L" and "LL".\nThe following code can pass all the test cases. Hope it helps!\n```\nclass Solution {\n    public boolean canChange(String start, String target) {\n        int i = 0;\n        int j = 0;\n        int n = start.length();\n        \n        while (i < n || j < n) {\n            while (i < n && start.charAt(i) == \'_\') i++;\n            while (j < n && target.charAt(j) == \'_\') j++;\n            \n            // should both reach the end to check the number of L and R\n            // e.g. "_L" and "LL"\n            if (i == n && j == n) return true;\n            if (i == n || j == n) return false; \n            \n            if (start.charAt(i) != target.charAt(j)) return false; // the same squence of R and L\n            \n            if (start.charAt(i) == \'L\' && i < j) return false; // can not move L to the right\n            if (start.charAt(i) == \'R\' && i > j) return false; // can not move R to the left\n            \n            i++;\n            j++;\n        }\n        \n        return i == n && j == n;\n    }\n}\n```
['Two Pointers', 'Java']