forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathString Without AAA or BBB.py
45 lines (40 loc) · 1.01 KB
/
String Without AAA or BBB.py
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
class Solution:
def strWithout3a3b(self, a: int, b: int) -> str:
if a<3 and b<3:
return 'a'*a+'b'*b
s=''
if a>=b:
k=a//b
if a//b!=a/b:
k+=1
if k>=3:
k=2
while a>0 or b>0:
if a>k:
s+='a'*k
else:
s+='a'*a
a-=k
if b>0:
s+='b'
b-=1
if a==b:
k=1
if a<b:
k=b//a
if b//a!=b/a:
k+=1
if k>=3:
k=2
while b>0 or a>0:
if b>k:
s+='b'*k
else:
s+='b'*b
b-=k
if a>0:
s+='a'
a-=1
if a==b:
k=1
return s