标签:
class Solution { public: string longestCommonPrefix(vector<string>& strs) { int len = strs.size(); if(len == 0) return ""; string prefix = strs[0]; for(int i = 1;i < len;i++) { if(prefix.length() == 0 || strs[i].length() == 0) return ""; int slen = prefix.length() < strs[i].length() ? prefix.length():strs[i].length(); int j; for(j = 0;j<slen;j++) { if(prefix[j] != strs[i][j]) break; } prefix = prefix.substr(0,j); } return prefix; } };
(leetcode)Longest Common Prefix
标签:
原文地址:http://www.cnblogs.com/chdxiaoming/p/4513095.html