LeetCode 剑指 Offer 17. 打印从1到最大的n位数
1 /** 2 * Note: The returned array must be malloced, assume caller calls free(). 3 */ 4 int* printNumbers(int n, int* returnSize){ 5 int top, i, j, *nums; 6 7 top = 1; 8 for (i=0; i<n; ++i) { 9 top = top * 10; 10 } 11 *returnSize = top - 1; 12 nums = malloc(sizeof(int) * (top - 1)); 13 memset(nums, 0, sizeof(int) * (top - 1)); 14 15 j = 0; 16 for (i=1; i<top; ++i) { 17 nums[j++] = i; 18 } 19 20 return nums; 21 }