1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
struct Solution;
impl Solution {
fn str_without3a3b(mut a: i32, mut b: i32) -> String {
if a == b {
let mut res = "".to_string();
for _ in 0..a {
res += "ab";
}
return res;
}
if a > b {
let mut res = "".to_string();
while a > 0 {
res += "a";
a -= 1;
if a > b {
res += "a";
a -= 1;
}
if b > 0 {
res += "b";
b -= 1;
}
}
return res;
}
if b > a {
let mut res = "".to_string();
while b > 0 {
res += "b";
b -= 1;
if b > a {
res += "b";
b -= 1;
}
if a > 0 {
res += "a";
a -= 1;
}
}
return res;
}
"".to_string()
}
}
#[test]
fn test() {
let a = 1;
let b = 2;
let res = "bab".to_string();
assert_eq!(Solution::str_without3a3b(a, b), res);
}