Skip to content

Commit fd64b5a

Browse files
authored
Merge pull request neetcode-gh#1618 from loczek/14-Longest-Common-Prefix
Create: 0014-longest-common-prefix.ts
2 parents 476af4d + e3f2165 commit fd64b5a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function longestCommonPrefix(strs: string[]): string {
2+
let res = "";
3+
4+
for (let i = 0; i < strs[0].length; i++) {
5+
for (const s of strs) {
6+
if (i == s.length || s[i] !== strs[0][i]) {
7+
return res;
8+
}
9+
}
10+
res += strs[0][i]
11+
}
12+
13+
return res;
14+
};

0 commit comments

Comments
 (0)