
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.
Given an array of 4 digits, return the largest 24 hour time that can be made.
The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight.
Return the answer as a string of length 5. If no valid time can be made, return an empty string.
Example 1:
Example 2:
Note:
A.length == 4
0 <= A[i] <= 9
这道题给了我们四个数字,让组成 24 小时制能表示的最大时间,并且数字可以重复。注意并不是任意给四个数字都能组成时间,因为小时的第一个数字只能是 0,1,2 三个数字,并且若第一个数字是2,第二个数字只能是 0,1,2,3 这四个数。且分钟的第一个数字必须小于6,这些都是表示时间的一些规则,毕竟一天只有 24 个小时,一个小时只有 60 分钟。最简单暴力的方法就是遍历所有的排列情况,然后去验证当前顺序是否可以正确的表示 24 小时制的时间。想偷懒的话可以使用 STL 内置的 next_permutation 方法来快速返回下一个排列,但是注意要先给数组排个序,使数组变为升序的,不然若直接给个降序数组,该函数没法返回下一个排列。给数组排序还有个好处就是让小的数字到前面,因为表示小时的数字比较小。得到一个排列后,看组成小时的两个数字是否小于等于 23,且表示分钟的两个数字是否小于等于 59,若都满足的话,则更新结果 res 为当前的排列即可,参见代码如下:
解法一:
你可能不屑于用 STL 内置函数来做,觉得简直是在耍赖,不能忍。那么下面就用一般的写法吧,反正只有四个数字,使用三个 for 循环就搞定了,分别用 i,j,k,6-i-j-k,来表示某个排列四个数字在原数组中的坐标,得到了排列顺序后,就可以分别组成小时和分钟的字符串表示了,但是需要注意的时候,由于此时是无序的,所以更新结果 res 的时候,要多加一个条件,当新的排序时间大于 res 时,才能更新,参见代码如下:
解法二:
之前的方法都是各种捣鼓数组A,下面来看一种遍历所有时间组合的解法。因为小时只有 24 个数组,分钟只有 60 个数字,可以用两个 for 循环遍历所有的时间组合,然后反向去验证这四个数字是否和A中的数字相同,为了快速验证,使用一个数组来记录每个数字的出现次数。由于小时和分钟都是两位数,只能用除以 10 或者对 10 取余来分别取出十位和个位上的数字。这里可以进行一个小优化,因为小于 10 的话,十位上的数字就是0,可以省去除法操作。等统计好了数字后,遍历数组A,每次减去对应位置的数字,当次数变成负数的时候,说明A中没有足够的该数字,使用一个布尔型变量来标记当前排列不行,并 break 掉。若某个排列可以由A组成的话,就要开始拼接时间字符串,如果是 Java 的话,那就非常的简单方便了,直接用
String.format("%02d:%02d", h, m)
就可以了,但是 C++ 比较麻烦,还得手动判断并加首位0,这简直就是把人往 Java 阵营推啊,参见代码如下:解法三:
Github 同步地址:
#949
参考资料:
https://leetcode.com/problems/largest-time-for-given-digits/submissions/
https://leetcode.com/problems/largest-time-for-given-digits/discuss/207126/Elegant-C%2B%2B-solution!)
https://leetcode.com/problems/largest-time-for-given-digits/discuss/202234/Java-Super-Short-Solution-!!!
https://leetcode.com/problems/largest-time-for-given-digits/discuss/200693/JavaPython-3-11-liner-O(64)-w-comment-6-ms.
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: