Skip to content

Commit f792dc8

Browse files
authored
Create generate-a-string-with-characters-that-have-odd-counts.cpp
1 parent ac1bdae commit f792dc8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
string generateTheString(int n) {
7+
auto result = string(n - 1, 'a');
8+
result.push_back(n % 2 ? 'a' : 'b');
9+
return result;
10+
}
11+
};

0 commit comments

Comments
 (0)