1. How I sloved

    I declared ‘output’. If ‘n’ is even, ‘a’ is appended to ‘output’. And ‘b’ is appended to ‘output’ for ‘n-1’ times.

2. Code

class Solution:
    def generateTheString(self, n: int) -> str:
        output = ''
        if n%2==0:
            output += 'a'
        else:
            output += 'b'
        for _ in range(1,n):
            output += 'b'
        return output

3. Result

        Runtime : 28 ms(78.92%), Memory usage : 13.8 MB(52.75%)
        (Runtime can be different by a system even if it is a same code.)

Check out the my GitHub repo for more info on the code. If you have questions, you can leave a reply on this post.