Skip to content

Commit eec318e

Browse files
longest common prefix
1 parent 1ca4dad commit eec318e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cSpell.words": ["MCMXCIV", "Palindrom"]
2+
"cSpell.words": ["MCMXCIV", "Palindrom", "strs"]
33
}

14-longestCommonPrefix.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const longestCommonPrefix = (strs) => {
2+
if (strs.length === 0) return '';
3+
let result = '';
4+
for (let i = 0; i < strs[0].length; i++) {
5+
for (let j = 1; j < strs.length; j++) {
6+
if (strs[j][i] !== strs[0][i]) return result;
7+
}
8+
result += strs[0][i];
9+
}
10+
return result;
11+
};
12+
13+
console.log(longestCommonPrefix(['flower', 'flow', 'flight']));

9-palindrom.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//-121 is palindrom or not?
21

32
function isPalindrom(num) {
43
let temp = num;

0 commit comments

Comments
 (0)