Skip to content

Commit 8e2640c

Browse files
committed
14
1 parent 3814a30 commit 8e2640c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string[]} strs
3+
* @return {string}
4+
*/
5+
6+
// 인덱스 0의 단어를 기준으로 잡고 그 다음 단어와 겹치는 글자들이 있으면 킾해놓고 다음꺼에 그게 있는지 비교하고...?
7+
8+
var longestCommonPrefix = function(strs) {
9+
const list = [];
10+
for ( let i=1; i<strs.length; i++) {
11+
let temp = "";
12+
for (let j=0; j<strs[0].length; j++) {
13+
if (strs[0][j] == strs[i][j]) {
14+
temp += strs[0][j];
15+
}
16+
}
17+
list.push(temp)
18+
}
19+
return list.reduce((a,b) => a.length <= b.length ? a : b)
20+
};

0 commit comments

Comments
 (0)