1374. 生成每种字符都是奇数个的字符串
分奇偶性讨论即可
class Solution:
def generateTheString(self, n: int) -> str:
if n & 1:
return "a" * n
else:
return "a" * (n - 1) + "b"
class Solution {
public:
string generateTheString(int n) {
if (n & 1)
{
return string(n, 'a');
}
else
return string(n - 1, 'a') + 'b';
}
};