My solution for coursera's algorithm (by Robert Sedgewick et al.) class.