aboutsummaryrefslogtreecommitdiff
path: root/other/string_without_3a3b.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/string_without_3a3b.cpp')
-rw-r--r--other/string_without_3a3b.cpp38
1 files changed, 0 insertions, 38 deletions
diff --git a/other/string_without_3a3b.cpp b/other/string_without_3a3b.cpp
deleted file mode 100644
index 738d000..0000000
--- a/other/string_without_3a3b.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-// 984. String Without AAA or BBB
-#include "leetcode.h"
-
-/*
- * given two integers 'a' and 'b', return any string 's' such that
- * - 's' has length 'a + b' and contains exactly 'a' a letters and exactly 'b' b
- * letters.
- * - the substring 'aaa' does not occur in 's' and
- * - the substring 'bbb' does not occur in 's'
- */
-
-class Solution {
-public:
- string strWithout3a3b(int a, int b) {
- string ans = "";
- int cnta = 0, cntb = 0, total = a + b;
- for (int i = 0; i < total; i++) {
- if ((b >= a && cntb < 2) || (cnta == 2 && b)) {
- ans += 'b';
- b--;
- cntb++;
- cnta = 0;
- } else if ((a >= b && cnta < 2) || (cntb == 2 && a)) {
- ans += 'a';
- a--;
- cnta++;
- cntb = 0;
- }
- }
- return ans;
- }
-};
-
-int main() {
- Solution obj;
- cout << obj.strWithout3a3b(1, 2) << endl; // expect: "abb"
- cout << obj.strWithout3a3b(4, 1) << endl; // expect: "aabaa"
-}