标签:公共前缀 turn else amp efi code ret back 最长公共前缀
1 //暴力求解 2 class Solution 3 { 4 public: 5 string longestCommonPrefix(vector<string>& strs) 6 { 7 if(strs.empty()) return ""; 8 int n = strs.size(); 9 int min_length = strs[0].size(); 10 for(int i = 0;i < strs.size();i ++) 11 { 12 if(min_length > strs[i].size()) min_length = strs[i].size(); 13 } 14 15 string res; 16 for(int i = 0;i < min_length;i ++) 17 { 18 char temp = strs[0][i]; 19 int j = 0; 20 for(;j < n;j ++) 21 { 22 if(temp != strs[j][i]) break; 23 } 24 if(j == n) res.push_back(temp); 25 else break; 26 } 27 return res; 28 } 29 };
标签:公共前缀 turn else amp efi code ret back 最长公共前缀
原文地址:https://www.cnblogs.com/yuhong1103/p/12499144.html