solution to Longest Common Prefix