Skip to content

Commit ad9fc98

Browse files
committed
[LEET] 547 Longest Common Prefix (Easy)
1 parent b8e9fb1 commit ad9fc98

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

이용훈/9주차/260223.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string[]} strs
3+
* @return {string}
4+
*/
5+
var longestCommonPrefix = function(strs) {
6+
for (let i = 0; i < strs[0].length; i++) {
7+
const ch = strs[0][i];
8+
9+
for (let j = 1; j < strs.length; j++) {
10+
if (i >= strs[j].length || strs[j][i] !== ch) {
11+
return strs[0].slice(0, i);
12+
}
13+
}
14+
}
15+
16+
return strs[0];
17+
};

0 commit comments

Comments
 (0)