Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
39 lines (33 loc) · 1009 Bytes

File metadata and controls

39 lines (33 loc) · 1009 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package leetcode.traceBack;
import java.util.ArrayList;
import java.util.List;
public class leetcode984 {
public String strWithout3a3b(int A, int B) {
StringBuilder ans = new StringBuilder();
while (A > 0 || B > 0) {
boolean writeA = false;
int L = ans.length();
if (L >= 2 && ans.charAt(L-1) == ans.charAt(L-2)) {
/*
ans.charAt(L-1) == ans.charAt(L-2),出现重复元素
* */
if (ans.charAt(L-1) == 'b')
writeA = true;
} else {
if (A >= B) //控制 先写多的,
writeA = true;
}
if (writeA) {
A--;
ans.append('a');
} else {
B--;
ans.append('b');
}
}
return ans.toString();
}
public static void main(String[] args) {
new leetcode984().strWithout3a3b(1,2);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.