Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1950 from laitooo/0014-longest-common-…
Browse files Browse the repository at this point in the history
…prefix.dart

Create 0014-Longest-Common-Prefix.dart
  • Loading branch information
tahsintunan authored Jan 9, 2023
2 parents 43951f1 + c5356e8 commit 3f05d31
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dart/0014-longest-common-prefix.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
String longestCommonPrefix(List<String> strs) {
String res = "";
for (int i=0; i<strs[0].length; i++) {
for (String s in strs) {
if (i >= s.length || strs[0][i] != s[i]){
return res;
}
}
res += strs[0][i];
}
return res;
}
}

0 comments on commit 3f05d31

Please sign in to comment.