Skip to content

Commit f4825db

Browse files
authored
Create Solution.js
1 parent 46a2880 commit f4825db

File tree

1 file changed

+24
-0
lines changed
  • solution/3000-3099/3043.Find the Length of the Longest Common Prefix

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var longestCommonPrefix = function(arr1, arr2) {
2+
let set = new Set();
3+
4+
for (let x of arr1) {
5+
while (x > 0) {
6+
set.add(x);
7+
x = Math.floor(x / 10);
8+
}
9+
}
10+
11+
let ans = 0;
12+
13+
for (let x of arr2) {
14+
while (x > 0) {
15+
if (set.has(x)) {
16+
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
17+
break;
18+
}
19+
x = Math.floor(x / 10);
20+
}
21+
}
22+
23+
return ans;
24+
};

0 commit comments

Comments
 (0)