-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
// 1374. 生成每种字符都是奇数个的字符串 | ||
|
||
// 给你一个整数 n,请你返回一个含 n 个字符的字符串,其中每种字符在该字符串中都恰好出现 奇数次 。 | ||
|
||
// 返回的字符串必须只含小写英文字母。如果存在多个满足题目要求的字符串,则返回其中任意一个即可。 | ||
|
||
class Solution { | ||
public: | ||
string generateTheString(int n) { | ||
if(n%2){ | ||
return string(n,'a'); | ||
} | ||
return string(n-1,'a')+"b"; | ||
} | ||
}; |