the facebook hackerCup 2013:
[find the beauty of a string]
the linkage below gives a novel and clear solution using python:
http://notes.tweakblogs.net/blog/8648/facebook-hacker-cup-2013-qualification-round-problem-analysis.html
enumerate
(
sequence,
start=0
)
Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence:
>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]
Another important data structure: collection:
ps: IBM doc provides a series of docs about the collection in Java.
linkage : http://www.ibm.com/developerworks/cn/java/j-5things2.html
We mainly focus on the Counter object: A counter tool is provided to support convenient and rapid tallies
1> A Counter is a dict subclass for counting hashable objects.
2> Counter objects support three methods beyond those available for all dictionaries:
1) elements(): which can rebuild a list ( or iterator) easily.
2) most_common(n) : Return a list of the n most common elements and their counts from the most common to the least
3) subtract
3> Counter objects have a dictionary interface except that they return a zero count for missing items instead of raising a KeyError