http://oj.leetcode.com/problems/longest-common-prefix/
Write a function to find the longest common prefix string amongst an array of strings.
思路:
没什么技巧,第一行第一个字符拿出来和其它所有行的第一个字符比,然后第二个,第三个。如果碰到不相等或某行结束就中断。
1 class Solution { 2 public: 3 string longestCommonPrefix(vector<string> &strs) { 4 if (0 == strs.size()) { 5 return string(); 6 } 7 8 int i = 0; 9 bool stop = false; 10 11 while (!stop) { 12 char ch = '