Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #298 from mnnkhndlwl/main
Browse files Browse the repository at this point in the history
push dominoes.cpp
  • Loading branch information
Almas-Ali authored Oct 30, 2022
2 parents 03a98fd + 18b12ae commit c669291
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions C++/push dominoes.cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Solution {
public:
string pushDominoes(string s) {
int n = s.size();
int right = -1;
for(int i = 0;i<n;i++) {
if(s[i] == 'L') {
if(right == -1) {
for(int j = i-1;j>=0 and s[j] == '.';j--) {
s[j] = 'L';
}
}
else {
for (int j = right + 1, k = i - 1; j < k; ++j, --k) {
s[j] = 'R';
s[k] = 'L';
}
right = -1;
}
}
else if(s[i] == 'R') {
if(right != -1) {
for (int j = right + 1; j < i; ++j) s[j] = 'R';
}
right = i;
}
}
if (right != -1) {
for (int j = right + 1; j < n; ++j) s[j] = 'R';
}
return s;
}
};

0 comments on commit c669291

Please sign in to comment.