Skip to content

Commit fa67038

Browse files
authored
Update Solution.ts
1 parent 9223b1f commit fa67038

File tree

1 file changed

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

1 file changed

+6
-13
lines changed
Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
function longestCommonPrefix(arr1: number[], arr2: number[]): number {
2-
let set = new Set<number>();
3-
2+
const s: Set<number> = new Set<number>();
43
for (let x of arr1) {
5-
while (x > 0) {
6-
set.add(x);
7-
x = Math.floor(x / 10);
4+
for (; x; x = Math.floor(x / 10)) {
5+
s.add(x);
86
}
97
}
10-
11-
let ans = 0;
12-
8+
let ans: number = 0;
139
for (let x of arr2) {
14-
while (x > 0) {
15-
if (set.has(x)) {
10+
for (; x; x = Math.floor(x / 10)) {
11+
if (s.has(x)) {
1612
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
17-
break;
1813
}
19-
x = Math.floor(x / 10);
2014
}
2115
}
22-
2316
return ans;
2417
}

0 commit comments

Comments
 (0)