1
// Time complexity: O(N)2
// Space complexity: O(N), where N is the length of input string4
public String pushDominoes(String dominoes) {5
// ask whether dominoes could be null6
final int N = dominoes.length();7
if (N <= 1) return dominoes;8
char[] res = dominoes.toCharArray();13
} else if (res[i] == 'L') { // push left15
while (j >= 0 && res[j] == '.') {19
} else { // res[i] == 'R'21
while (j < N && res[j] == '.') { // try to find 'R' or 'L' in the right side24
if (j < N && res[j] == 'L') { // if found 'L', push left and right25
for (int l = i + 1, r = j - 1; l < r; l++, r--) {30
} else { // if no 'L', push right37
return String.valueOf(res);