leetcode 1374. Generate a String With Characters That Have Odd Counts

问题来自 leetcode 1374. Generate a String With Characters That Have Odd Counts


 

class Solution {
public:
    string generateTheString(int n) {
        if (n % 2 == 0) {
            return string(n-1, 'a') + string(1, 'b');
        } else {
            return string(n, 'a');
        }
    }
};

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.