Leetcode 14. Longest Common Prefix | | Leetcode 14. Longest Common Prefix 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution1234567891011121314151617181920class Solution {public: string longestCommonPrefix(vector<string>& strs) { string result = ""; if(strs.size() == 0) { return result; } string pattern = strs[0]; for(int i = 0; i < pattern.length(); i++) { char ch = pattern[i]; for(string s : strs) { if(s[i] != ch) { return result; } } result += ch; } return result; }}; Reference https://leetcode.com/problems/longest-common-prefix/description/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏