链接:https://leetcode.cn/problems/generate-a-string-with-characters-that-have-odd-counts/solution/by-xun-ge-v-hiex/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
题目要求生成奇数个字符,很显然分情况讨论即可
- char * generateTheString(int n){
- char * str = malloc(sizeof(char) * (n+1));//定义字符串
- memset(str, 97, sizeof(char) * n);//初始化为a
- if(n % 2 == 0)//判断奇偶
- {
- str[0] = 'm';
- }
- str[n] = '\0';
- return str;
- }
-
- 作者:xun-ge-v
- 链接:https://leetcode.cn/problems/generate-a-string-with-characters-that-have-odd-counts/solution/by-xun-ge-v-hiex/
- 来源:力扣(LeetCode)
- 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。