Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 420ec5e

Browse files
fix: update solutions to lc problem: No.3043 (doocs#3557)
1 parent 76e8b50 commit 420ec5e

File tree

4 files changed

+88
-12
lines changed

4 files changed

+88
-12
lines changed

‎solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README.md‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ func longestCommonPrefix(arr1 []int, arr2 []int) (ans int) {
176176
function longestCommonPrefix(arr1: number[], arr2: number[]): number {
177177
const s: Set<number> = new Set<number>();
178178
for (let x of arr1) {
179-
for (; x; x = (x / 10)|0) {
180-
s.add(x%10);
179+
for (; x; x = Math.floor(x / 10)) {
180+
s.add(x);
181181
}
182182
}
183183
let ans: number = 0;
184184
for (let x of arr2) {
185-
for (; x; x = (x / 10)|0) {
186-
if (s.has(x%10)) {
185+
for (; x; x = Math.floor(x / 10)) {
186+
if (s.has(x)) {
187187
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
188188
}
189189
}
@@ -192,6 +192,33 @@ function longestCommonPrefix(arr1: number[], arr2: number[]): number {
192192
}
193193
```
194194

195+
#### JavaScript
196+
197+
```js
198+
/**
199+
* @param {number[]} arr1
200+
* @param {number[]} arr2
201+
* @return {number}
202+
*/
203+
var longestCommonPrefix = function (arr1, arr2) {
204+
const s = new Set();
205+
for (let x of arr1) {
206+
for (; x; x = Math.floor(x / 10)) {
207+
s.add(x);
208+
}
209+
}
210+
let ans = 0;
211+
for (let x of arr2) {
212+
for (; x; x = Math.floor(x / 10)) {
213+
if (s.has(x)) {
214+
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
215+
}
216+
}
217+
}
218+
return ans;
219+
};
220+
```
221+
195222
<!-- tabs:end -->
196223

197224
<!-- solution:end -->

‎solution/3000-3099/3043.Find the Length of the Longest Common Prefix/README_EN.md‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ func longestCommonPrefix(arr1 []int, arr2 []int) (ans int) {
174174
function longestCommonPrefix(arr1: number[], arr2: number[]): number {
175175
const s: Set<number> = new Set<number>();
176176
for (let x of arr1) {
177-
for (; x; x = (x / 10)|0) {
178-
s.add(x%10);
177+
for (; x; x = Math.floor(x / 10)) {
178+
s.add(x);
179179
}
180180
}
181181
let ans: number = 0;
182182
for (let x of arr2) {
183-
for (; x; x = (x / 10)|0) {
184-
if (s.has(x%10)) {
183+
for (; x; x = Math.floor(x / 10)) {
184+
if (s.has(x)) {
185185
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
186186
}
187187
}
@@ -190,6 +190,33 @@ function longestCommonPrefix(arr1: number[], arr2: number[]): number {
190190
}
191191
```
192192

193+
#### JavaScript
194+
195+
```js
196+
/**
197+
* @param {number[]} arr1
198+
* @param {number[]} arr2
199+
* @return {number}
200+
*/
201+
var longestCommonPrefix = function (arr1, arr2) {
202+
const s = new Set();
203+
for (let x of arr1) {
204+
for (; x; x = Math.floor(x / 10)) {
205+
s.add(x);
206+
}
207+
}
208+
let ans = 0;
209+
for (let x of arr2) {
210+
for (; x; x = Math.floor(x / 10)) {
211+
if (s.has(x)) {
212+
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
213+
}
214+
}
215+
}
216+
return ans;
217+
};
218+
```
219+
193220
<!-- tabs:end -->
194221

195222
<!-- solution:end -->
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} arr1
3+
* @param {number[]} arr2
4+
* @return {number}
5+
*/
6+
var longestCommonPrefix = function (arr1, arr2) {
7+
const s = new Set();
8+
for (let x of arr1) {
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+
for (; x; x = Math.floor(x / 10)) {
16+
if (s.has(x)) {
17+
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
18+
}
19+
}
20+
}
21+
return ans;
22+
};

‎solution/3000-3099/3043.Find the Length of the Longest Common Prefix/Solution.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
function longestCommonPrefix(arr1: number[], arr2: number[]): number {
22
const s: Set<number> = new Set<number>();
33
for (let x of arr1) {
4-
for (; x; x = (x / 10)|0) {
5-
s.add(x%10);
4+
for (; x; x = Math.floor(x / 10)) {
5+
s.add(x);
66
}
77
}
88
let ans: number = 0;
99
for (let x of arr2) {
10-
for (; x; x = (x / 10)|0) {
11-
if (s.has(x%10)) {
10+
for (; x; x = Math.floor(x / 10)) {
11+
if (s.has(x)) {
1212
ans = Math.max(ans, Math.floor(Math.log10(x)) + 1);
1313
}
1414
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /