2020-02-03 20:43:46
问题描述:
问题求解:
public boolean canTransform(String start, String end) { int n = start.length(); List<int[]> s = new ArrayList<>(); List<int[]> e = new ArrayList<>(); for (int i = 0; i < n; i++) { char c = start.charAt(i); if (c == 'L' || c == 'R') { s.add(new int[]{c - 'a', i}); } c = end.charAt(i); if (c == 'L' || c == 'R') { e.add(new int[]{c - 'a', i}); } } if (s.size() != e.size()) return false; for (int i = 0; i < s.size(); i++) { int[] cs = s.get(i); int[] ce = e.get(i); if (cs[0] != ce[0]) return false; if (cs[0] == 'L' - 'a' && cs[1] < ce[1]) return false; if (cs[0] == 'R' - 'a' && cs[1] > ce[1]) return false; } return true; }