Created
April 1, 2020 04:54
-
-
Save wushbin/8e8f2745f67d9fc557fa622461c56b11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public boolean canTransform(String start, String end) { | |
| int pt1 = 0, pt2 = 0; | |
| int len1 = start.length(); | |
| int len2 = end.length(); | |
| while(pt1 < len1 || pt2 < len2) { | |
| // find not X | |
| while(pt1 < len1 && start.charAt(pt1) == 'X') { | |
| pt1++; | |
| } | |
| // find not X | |
| while(pt2 < len2 && end.charAt(pt2) == 'X') { | |
| pt2++; | |
| } | |
| if (pt1 == len1 && pt2 == len2) { | |
| return true; | |
| } | |
| if (pt1 == len1 || pt2 == len2) { | |
| return false; | |
| } | |
| if (start.charAt(pt1) != end.charAt(pt2)) { | |
| return false; | |
| } | |
| if (start.charAt(pt1) == 'L' && pt1 < pt2) { | |
| return false; | |
| } | |
| if (start.charAt(pt1) == 'R' && pt1 > pt2) { | |
| return false; | |
| } | |
| pt1++; | |
| pt2++; | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment