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 fa67038 commit cc15596Copy full SHA for cc15596
solution/3000-3099/3043.Find the Length of the Longest Common Prefix/Solution.js
@@ -1,24 +1,22 @@
1
+/**
2
+ * @param {number[]} arr1
3
+ * @param {number[]} arr2
4
+ * @return {number}
5
+ */
6
var longestCommonPrefix = function (arr1, arr2) {
- let set = new Set();
-
7
+ const s = new Set();
8
for (let x of arr1) {
- while (x > 0) {
- set.add(x);
- x = Math.floor(x / 10);
9
+ for (; x; x = Math.floor(x / 10)) {
10
+ s.add(x);
11
}
12
13
let ans = 0;
14
for (let x of arr2) {
15
- if (set.has(x)) {
16
+ if (s.has(x)) {
17
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
- break;
18
19
20
21
22
23
return ans;
24
};
0 commit comments