- 模拟
如果n为奇数,则返回n个a;如果n为偶数,则返回n-1个a和1个b
class Solution {
public String generateTheString(int n) {
StringBuffer sb = new StringBuffer();
if (n % 2 == 1) {
return sb.append("a".repeat(n)).toString();
}
return sb.append("a".repeat(n - 1)).append("b").toString();
}
}
标签:字符,每种,奇数,leetcode1374,字符串,sb,append
From: https://www.cnblogs.com/xzh-yyds/p/16589906.html