We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5154795 commit 9829403Copy full SHA for 9829403
0014-longest-common-prefix/0014-longest-common-prefix.cpp
@@ -0,0 +1,28 @@
1
+class Solution {
2
+public:
3
+ string longestCommonPrefix(vector<string>& strs) {
4
+
5
+ string solution = "";
6
7
+ for(int i=0; i<strs[0].length(); i++) {
8
9
+ char curr = strs[0][i];
10
+ bool flag = false;
11
12
+ for(int j=0; j<strs.size(); j++) {
13
+ if(strs[j][i] != curr) {
14
+ flag = true;
15
+ break;
16
+ }
17
18
19
+ if(flag) return solution;
20
21
+ solution += curr;
22
23
24
25
+ return solution;
26
27
28
+};
0 commit comments