We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0bb14db commit 9b76e40Copy full SHA for 9b76e40
1 file changed
14_Longest Common Prefix
@@ -0,0 +1,19 @@
1
+
2
+class Solution {
3
+public:
4
+ string longestCommonPrefix(vector<string>& strs) {
5
6
+ while (strs.size()==0) return "";
7
8
+ string prefix = strs[0];
9
10
+ for(int i = 1; i < strs.size(); i++){
11
+ while(strs[i].substr(0,prefix.size()) != prefix){
12
+ prefix = prefix.substr(0, prefix.size() - 1);
13
+ }
14
15
16
+ return prefix;
17
18
19
+};
0 commit comments