Skip to content

Commit 842d342

Browse files
committed
.
1 parent 66ef027 commit 842d342

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

string-without-aaa-or-bbb.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// String Without AAA or BBB
2+
impl Solution {
3+
pub fn str_without3a3b(mut a: i32, mut b: i32) -> String {
4+
use std::mem::swap;
5+
let mut ans = vec![];
6+
let mut A = b'a';
7+
let mut B = b'b';
8+
if a < b { swap(&mut a, &mut b); swap(&mut A, &mut B); }
9+
while a > 0 {
10+
ans.push(A);
11+
if a-1 <= b { a -= 1; }
12+
else { ans.push(A); a -= 2; }
13+
if b > 0 { ans.push(B); b -= 1; }
14+
}
15+
String::from_utf8_lossy(&ans).into_owned()
16+
}
17+
}

0 commit comments

Comments
 (0)