
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.
A character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:
This is how the UTF-8 encoding would work:
Given an array of integers representing the data, return whether it is a valid utf-8 encoding.
Note:
The input is an array of integers. Only the least significant 8 bits of each integer is used to store the data. This means each integer represents only 1 byte of data.
Example 1:
Example 2:
这道题考察我们 UTF-8 编码,这种互联网所采用的通用的编码格式的产生是为了解决ASCII只能表示英文字符的局限性,和统一 Unicode 的实现方式。下面这段摘自维基百科 UTF-8 编码:
对于 UTF-8 编码中的任意字节B,如果B的第一位为0,则B独立的表示一个字符(ASCII 码);
如果B的第一位为1,第二位为0,则B为一个多字节字符中的一个字节(非 ASCII 字符);
如果B的前两位为1,第三位为0,则B为两个字节表示的字符中的第一个字节;
如果B的前三位为1,第四位为0,则B为三个字节表示的字符中的第一个字节;
如果B的前四位为1,第五位为0,则B为四个字节表示的字符中的第一个字节;
因此,对 UTF-8 编码中的任意字节,根据第一位,可判断是否为 ASCII 字符;根据前二位,可判断该字节是否为一个字符编码的第一个字节;根据前四位(如果前两位均为1),可确定该字节为字符编码的第一个字节,并且可判断对应的字符由几个字节表示;根据前五位(如果前四位为1),可判断编码是否有错误或数据传输过程中是否有错误。
那么根据上面的描述,我们可以先来判断第一位,如果是0的话,则说明是 ASCII 码,我们直接跳过,判断方法是只要比二进制数 10000000 小的数第一位肯定是0,然后我们来处理第一位是1的情况,由于第一位的1只是个标识符,后面连续跟的1的个数才是表示后面的字节的个数,我们可以统一从第一位开始连续1的个数,然后减去1就是后面的字节的个数,我想的办法是如果该数字大于等于 128,则表示第一位是1,然后减去 128,如果得到的数大于等于 64,则表示第二位是1,依次类推就可以得到连续的个数 cnt,我们要注意 10000000 这个数是不合法的,所以当 cnt 为1的时候直接返回 false,还有就是连续1的个数不能超过4个,当 cnt 大于4时也是不合法的。即便是当 cnt 为 [2, 4] 之间的数,若后面没有跟正确个数的字节,还是非法的,所以当 cnt > n-i 时还是 false。我们得到了合法的 cnt 的个数,只要验证后面的字节是否是以 10 开头的数即可,验证方法也很简单,只要这个数在 10000000 ~ 10111111 范围之间,则一定是 10 开头的,参见代码如下:
解法一:
在论坛里看到了一种非常简洁的方法,大神就是大神啊,这种方法也是要记连续1的个数,如果是标识字节,先将其向右平移五位,如果得到 110,则说明后面跟了一个字节,否则向右平移四位,如果得到 1110,则说明后面跟了两个字节,否则向右平移三位,如果得到 11110,则说明后面跟了三个字节,否则向右平移七位,如果为1的话,说明是 10000000 这种情况,不能当标识字节,直接返回 false。在非标识字节中,向右平移六位,如果得到的不是 10,则说明不是以 10 开头的,直接返回 false,否则 cnt 自减1,成功完成遍历返回 true,参见代码如下:
解法二:
Github 同步地址:
#393
参考资料:
https://leetcode.com/problems/utf-8-validation/
https://leetcode.com/problems/utf-8-validation/discuss/87464/Bit-Manipulation-Java-6ms
https://leetcode.com/problems/utf-8-validation/discuss/87462/Concise-C%2B%2B-implementation
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: