
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.
We have a string
S
of lowercase letters, and an integer arrayshifts
.Call the shift of a letter, the next letter in the alphabet, (wrapping around so that
'z'
becomes'a'
).For example,
shift('a') = 'b'
,shift('t') = 'u'
, andshift('z') = 'a'
.Now for each
shifts[i] = x
, we want to shift the firsti+1
letters ofS
,x
times.Return the final string after all such shifts to
S
are applied.Example 1:
Note:
1 <= S.length = shifts.length <= 20000
0 <= shifts[i] <= 10 ^ 9
这道题让我们对字母进行漂移,给了一个 shifts 数组,里面是对应对需要漂移值,但是需要注意的是,shifts[i] 表示对于原字符串 [0, i] 范围内的所有的字符都进行 shifts[i] 的漂移,那么实际上第一个字母其实把 shifts 数组所有的数字都漂移了一遍,而第二个字母则是把 shifts 数组从第二个数字开始到最后的所有数字都漂移了,而最后一个字母就只漂移了最后一个数字。这不就是一个反向累加和数组么,只要建立了反向累加和数组,那么每个位子上的数字就是对应的字母的漂移值了。为了节省空间,我们就不另建数组了,直接在 shifts 数组上累加就行了,注意累加值要对 26 取余,因为累加和数组可能会整型溢出,取余后就不会有这个问题,而且由于字母漂移 2 6次后,都会回到原来的位置,所以对 26 取余并不会影响到最后的结果。
反向累加和数组建立好了之后,就要开始对字母进行漂移了,这里还有个需要注意的地方,不能直接用原字母加上漂移值,因为一旦超过了 'z' 的时候,是需要从 'a' 重新的开始的,为了处理所有的情况,可以使用一个很常用的 trick,就是先算出字母到 'a' 之间的距离,然后加上漂移值,再对 26 取余,这就是漂移后与 'a' 的距离了,再加上 'a' 变成字母即可,参见代码如下:
Github 同步地址:
#848
参考资料:
https://leetcode.com/problems/shifting-letters/
https://leetcode.com/problems/shifting-letters/discuss/137906/C%2B%2BJavaPython-Easy-Understood
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: