Add solution to problem #39

Added solution to problem #39