From 7c60dee83b436e8e8a667bf9f191beced8de4fc3 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Mon, 10 Mar 2025 00:36:13 -0600 Subject: chore: move cpp and rust code to directory --- other/push_dominoes.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 other/push_dominoes.cpp (limited to 'other/push_dominoes.cpp') 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 + +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"); +} -- cgit v1.2.3