
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.
The main site for Archive Team is at archiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.
This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by the Wayback Machine, providing a path back to lost websites and work.
Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.
The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.
Return all non-negative integers of length
n
such that the absolute difference between every two consecutive digits isk
.Note that every number in the answer must not have leading zeros except for the number
0
itself. For example,01
has one leading zero and is invalid, but0
is valid.You may return the answer in any order.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
2 <= n <= 9
0 <= k <= 9
这道题说是让组个n位的正整数,任意相邻两位上的数字之差为k,并说明了不能有起始位为0的多位数。其实这就是个拼数的问题,就一位一位来凑数字就行了,题目中说了n是大于等于2的,所以至少是个两位数,所以第一位数肯定不是0,所以把1到9放到数组中开始凑数字。总共n位,现在已经有了一位了,还需要凑 n-1 位,所以循环 n-1 次。在循环中,新建一个数组 cur,然后遍历 res 数组中的数字,用对 10 取余的方法取出末尾数字 digit,然后看 digit 加上k是否小于等于9,是的话将 digit+k 加到末尾位,并将新数组加入数组 cur。然后再判断,若k不等于0,且 digit 减k大于等于0,则将 digit-k 加到末尾位,并将新数组加入数组 cur。判断k不等于0的原因是为了避免 digit+k 和 digit-k 相等,从而产生重复结果。遍历完了结果 res 中的数字,将 res 更新为 cur 数组,参见代码如下:
解法一:
我们也可以使用递归的写法,对于每个起始数字1到9,都调用一个递归函数,整体思路和上面的迭代解法大同小异,可以参考上面的讲解,参见代码如下:
解法二:
Github 同步地址:
#967
参考资料:
https://leetcode.com/problems/numbers-with-same-consecutive-differences/
https://leetcode.com/problems/numbers-with-same-consecutive-differences/discuss/211193/C%2B%2B-DFS
https://leetcode.com/problems/numbers-with-same-consecutive-differences/discuss/211183/JavaC%2B%2BPython-Iterative-Solution
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: