那个题好像没有什么意思,因为俺是按照难易度排序然后开始刷题的哈。 第二题是258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. 就是给出一个非负整数,然后不断地加,加到个位数。加的规则如例子所示:38-->3+8=11-->1+1=2;再举一个例子,456-->4+5+6=15--->1+5=6. 给出的函数格式: int addDigits(int num) { } 尽量 不要用o(1)时间复杂度下面的递归算法。
第5个题:283. Move Zeroes 这个题不是很难,之前用python写的时候很简单。要求比较多。 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0]. Note: You must do this in-place without making a copy of the array. Minimize the total number of operations. 将给定数组中的零移动到最后,并保持整个数组的相对顺序。 例如;[0,1,0,3,12]变化之后是[1,2,12,0,0] 有两点要求: 1、不得制作给定数组的副本。 2、尽量减少操作步骤。 说白了就是最小的时间和空间复杂度。 函数格式: void moveZeroes(int* nums, int numsSize) { }