Skip to content

Commit 81b74b4

Browse files
committed
leetcode_14
1 parent 18dfd8b commit 81b74b4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

14_Longest_Common_Prefix.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
string longestCommonPrefix(vector<string>& strs) {
4+
if(strs.empty())
5+
return "";
6+
for(int i=0; i<strs[0].size(); i++){
7+
char c = strs[0][i];
8+
for(int j=1; j<strs.size(); j++){
9+
if(i==strs[j].size() || c!=strs[j][i])
10+
return strs[0].substr(0,i);
11+
}
12+
}
13+
return strs[0];
14+
}
15+
};

0 commit comments

Comments
 (0)