Skip to content

Commit cc15596

Browse files
authored
Update Solution.js
1 parent fa67038 commit cc15596

File tree

1 file changed

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

1 file changed

+10
-12
lines changed
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1+
/**
2+
* @param {number[]} arr1
3+
* @param {number[]} arr2
4+
* @return {number}
5+
*/
16
var longestCommonPrefix = function (arr1, arr2) {
2-
let set = new Set();
3-
7+
const s = new Set();
48
for (let x of arr1) {
5-
while (x > 0) {
6-
set.add(x);
7-
x = Math.floor(x / 10);
9+
for (; x; x = Math.floor(x / 10)) {
10+
s.add(x);
811
}
912
}
10-
1113
let ans = 0;
12-
1314
for (let x of arr2) {
14-
while (x > 0) {
15-
if (set.has(x)) {
15+
for (; x; x = Math.floor(x / 10)) {
16+
if (s.has(x)) {
1617
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
17-
break;
1818
}
19-
x = Math.floor(x / 10);
2019
}
2120
}
22-
2321
return ans;
2422
};

0 commit comments

Comments
 (0)