LeetCode 984. 不含 AAA 或 BBB 的字符串

题目描述

🔥 984. 不含 AAA 或 BBB 的字符串

思路分析

贪心

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
func strWithout3a3b(A int, B int) string {
	res := make([]string, 0)
	a, b := "a", "b"
	if A < B {
		A, B = B, A
		a, b = b, a
	}
	for A > 0 || B > 0 {
		if A > 0 {
			res = append(res, a)
			A--
		}
		if A > B {
			res = append(res, a)
			A--
		}
		if B > 0 {
			res = append(res, b)
			B--
		}
	}
	return strings.Join(res, "")
}

🍏 点击查看 Java 题解

1
write your code here
本文作者:
本文链接: https://hgnulb.github.io/blog/25121489
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处!