Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

return string consistent of n lowercase letters such is all letters occurs an odd number

 public String generateTheString(int n) {
        int count = (n % 2 == 0) ? n - 1 : n;
        StringBuilder result  = new StringBuilder();

        result.append("x".repeat(Math.max(0, count)));

        if( n % 2 == 0){
            result.append('y');
        }
        return result.toString();
    }
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #return #string #consistent #lowercase #letters #letters #occurs #odd #number
ADD COMMENT
Topic
Name
4+5 =