Longest Common Prefix LeetCode solution in JavaScript

1
var longestCommonPrefix = function (strs) {
2
let commonStr = strs[0];
3
for (let i = 1; i < strs.length; i++) {
4
let currentStr = strs[i];
5
for (let j = 0; j < commonStr.length; j++) {
6
if (commonStr[j] !== currentStr[j]) {
7
commonStr = currentStr.slice(0, j);
8
break;
9
}
10
}
11
}
12
return commonStr;
13
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0