
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.
In a deck of cards, each card has an integer written on it.
Return
true
if and only if you can chooseX >= 2
such that it is possible to split the entire deck into 1 or more groups of cards, where:X
cards.Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Note:
1 <= deck.length <= 10000
0 <= deck[i] < 10000
这道题给了一堆牌,问我们能不能将这副牌分成若干堆,每堆均有X个,且每堆的牌数字都相同(这里不考虑花色)。既然要将相同的牌归类,肯定要统计每种牌出现的个数,所以使用一个 HashMap 来建立牌跟其出现次数之间的映射。由于每堆X个,则若果某张牌的个数小于X,则肯定无法分,所以X的范围是可以确定的,为 [2, mn],其中 mn 是数量最少的牌的个数。遍历一遍 HashMap,找出最小的映射值 mn,若 mn 小于2,可以直接返回 false。否则就从2遍历到 mn,依次来检验候选值X。检验的方法是看其他每种牌的个数是否能整除候选值X,不一定非要相等,比如 [1, 1, 2, 2, 2, 2], K=2 时就可以分为三堆 [1, 1], [2, 2], [2, 2],即相同的牌也可以分到其他堆里,所以只要每种牌的个数能整除X即可,一旦有牌数不能整除X了,则当前X一定不行,还得继续检验下一个X值;若所有牌数都能整除X,可以返回 true。循环结束后返回 false,参见代码如下:
解法一:
上面的解法是博主自己的解法,论坛上好多人使用了一个基于最大公约数 Greatest Common Divisor 的解法,写起来很简洁,但需要记住最大公约函数的写法,或者直接使用内置的 gcd 函数(感觉有点耍赖哈~)。其实原理都差不多,这里是找每种牌数之间的最大公约数,只要这个 gcd 是大于1的,就表示可以找到符合题意的X,参见代码如下:
解法二:
Github 同步地址:
#914
参考资料:
https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/
https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/discuss/175845/C%2B%2BJavaPython-Greatest-Common-Divisor
https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/discuss/309992/Java-Easy-to-understand-2-ms-faster-than-98.92-38.5-MB-less-than-99.23
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: