We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 9d668c6 + 0679f9f commit d6c844dCopy full SHA for d6c844d
java/0838-push-dominoes.java
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ public String pushDominoes(String dominoes) {
3
+ int len = dominoes.length();
4
+ Queue<Integer> q = new LinkedList<>();
5
+ char[] dom = dominoes.toCharArray();
6
+ for (int i = 0; i < len; i++)
7
+ if (dominoes.charAt(i) != '.') q.offer(i);
8
+
9
+ while (!q.isEmpty()) {
10
+ int i = q.poll();
11
+ char ch = dom[i];
12
+ if (dom[i] == 'R') {
13
+ if (i + 1 < len && dom[i + 1] == '.') {
14
+ if (i + 2 < len && dom[i + 2] == 'L') {
15
+ q.poll();
16
+ } else {
17
+ dom[i + 1] = 'R';
18
+ q.offer(i + 1);
19
+ }
20
21
+ } else if (i > 0 && dom[i - 1] == '.') {
22
+ dom[i - 1] = 'L';
23
+ q.offer(i - 1);
24
25
26
+ return String.valueOf(dom);
27
28
+}
0 commit comments