We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9223b1f commit fa67038Copy full SHA for fa67038
solution/3000-3099/3043.Find the Length of the Longest Common Prefix/Solution.ts
@@ -1,24 +1,17 @@
1
function longestCommonPrefix(arr1: number[], arr2: number[]): number {
2
- let set = new Set<number>();
3
-
+ const s: Set<number> = new Set<number>();
4
for (let x of arr1) {
5
- while (x > 0) {
6
- set.add(x);
7
- x = Math.floor(x / 10);
+ for (; x; x = Math.floor(x / 10)) {
+ s.add(x);
8
}
9
10
11
- let ans = 0;
12
+ let ans: number = 0;
13
for (let x of arr2) {
14
15
- if (set.has(x)) {
+ if (s.has(x)) {
16
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
17
- break;
18
19
20
21
22
23
return ans;
24
0 commit comments