From 66d1104fce77a994c8b1f2c0ad389ecc9be9f540 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:59:12 +0530 Subject: [PATCH] Create 3163. String Compression III --- 3163. String Compression III | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 3163. String Compression III diff --git a/3163. String Compression III b/3163. String Compression III new file mode 100644 index 0000000..cd104f4 --- /dev/null +++ b/3163. String Compression III @@ -0,0 +1,27 @@ +class Solution { +public: + string compressedString(string word) + { + string ans; + + int count = 0; + char prev = word[0]; + for(auto ch : word) + { + if(prev != ch or count == 9) + { + ans += to_string(count); + ans += prev; + prev = ch; + count = 0; + } + count += 1; + } + if(count) + { + ans += to_string(count); + ans += prev; + } + return ans; + } +};