Modified solution to make use of a STL container.