[Java/Python 3] Two simple logic readable codes, iterative and recursive versions.
If current result ends with aa, next char is b; if ends with bb, next char must be a.\n2. Other cases, if A > B, next char is a; otherwise, next char is b.\n\nj
1. If current result ends with `aa`, next char is `b`; if ends with `bb`, next char must be `a`.\n2. Other cases, if A > B, next char is `a`; otherwise, next char is `b`.\n\n```java\n    public String strWithout3a3b(int A, int B) {\n        StringBuilder sb = new StringBuilder(A + B);\n        while (A + B > 0) {\n            String s = sb.toString();\n            if (s.endsWith("aa")) {\n                sb.append("b");\n                --B;       \n            }else if (s.endsWith("bb")){\n                sb.append("a");\n                --A;\n            }else if (A >= B) {\n                sb.append("a");\n                --A;\n            }else {\n                sb.append("b");\n                --B;\n            }\n        }\n        return sb.toString();\n    }\n```\n```python\n    def strWithout3a3b(self, a: int, b: int) -> str:\n        ans = []\n        while a + b > 0:\n            if ans[-2 :] == [\'a\', \'a\']:\n                b -= 1\n                ans.append(\'b\')\n            elif ans[-2 :] == [\'b\', \'b\']:\n                a -= 1\n                ans.append(\'a\')    \n            elif a >= b:\n                a -= 1\n                ans.append(\'a\')\n            else:\n                b -= 1\n                ans.append(\'b\')\n        return \'\'.join(ans)\n```\n\nRecursive Version, inspired by @lbjlc\n \n```java\n    public String strWithout3a3b(int A, int B) {\n        if (A == 0 || B == 0) { return String.join("", Collections.nCopies(A + B, A == 0 ? "b" : "a")); } // if A or B is 0, return A \'a\'s or B \'b\'s.\n        if (A == B) { return "ab" + strWithout3a3b(A - 1, B - 1); }\n        if (A > B) { return "aab" + strWithout3a3b(A - 2, B - 1); }\n        return "bba" + strWithout3a3b(A - 1, B - 2);\n    }\n```\n```python\n    def strWithout3a3b(self, a: int, b: int) -> str:\n        if a * b == 0:\n            return \'a\' * a + \'b\' * b\n        elif a == b:\n            return \'ab\' * a\n        elif a > b:\n            return \'aab\' + self.strWithout3a3b(a - 2, b - 1)\n        return self.strWithout3a3b(a - 1, b - 2) + \'abb\'\n```
[]