diff options
author | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /other/push_dominoes.cpp | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip |
chore: move cpp and rust code to directory
Diffstat (limited to 'other/push_dominoes.cpp')
-rw-r--r-- | other/push_dominoes.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/other/push_dominoes.cpp b/other/push_dominoes.cpp new file mode 100644 index 0000000..859dad9 --- /dev/null +++ b/other/push_dominoes.cpp @@ -0,0 +1,31 @@ +#include "leetcode.h" +#include <string> + +class Solution { +public: + string pushDominoes(string dominoes) { + dominoes = 'L' + dominoes + 'R'; + string ans = ""; + for (int i = 0, j = 1; j < dominoes.size(); ++j) { + if (dominoes[j] == '.') + continue; + int middle = j - i - 1; + if (i > 0) + ans += dominoes[i]; + if (dominoes[i] == dominoes[j]) + ans += string(middle, dominoes[i]); + else if (dominoes[i] == 'L' && dominoes[j] == 'R') + ans += string(middle, '.'); + else + ans += string(middle / 2, 'R') + string(middle % 2, '.') + + string(middle / 2, 'L'); + i = j; + } + return ans; + } +}; + +int main() { + Solution obj; + cout << obj.pushDominoes("RR.L"); +} |