Skip to content

Commit fa7b5b4

Browse files
committed
feat: add solutions to lc problem: No.1394
1 parent 14379c3 commit fa7b5b4

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/1300-1399/1394.Find Lucky Integer in an Array/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ class Solution {
170170
}
171171
```
172172

173+
### **TypeScript**
174+
175+
```ts
176+
function findLucky(arr: number[]): number {
177+
const cnt = new Array(510).fill(0);
178+
for (const x of arr) {
179+
++cnt[x];
180+
}
181+
let ans = -1;
182+
for (let x = 1; x < cnt.length; ++x) {
183+
if (cnt[x] === x) {
184+
ans = x;
185+
}
186+
}
187+
return ans;
188+
}
189+
```
190+
173191
### **...**
174192

175193
```

solution/1300-1399/1394.Find Lucky Integer in an Array/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ class Solution {
140140
}
141141
```
142142

143+
### **TypeScript**
144+
145+
```ts
146+
function findLucky(arr: number[]): number {
147+
const cnt = new Array(510).fill(0);
148+
for (const x of arr) {
149+
++cnt[x];
150+
}
151+
let ans = -1;
152+
for (let x = 1; x < cnt.length; ++x) {
153+
if (cnt[x] === x) {
154+
ans = x;
155+
}
156+
}
157+
return ans;
158+
}
159+
```
160+
143161
### **...**
144162

145163
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function findLucky(arr: number[]): number {
2+
const cnt = new Array(510).fill(0);
3+
for (const x of arr) {
4+
++cnt[x];
5+
}
6+
let ans = -1;
7+
for (let x = 1; x < cnt.length; ++x) {
8+
if (cnt[x] === x) {
9+
ans = x;
10+
}
11+
}
12+
return ans;
13+
}

0 commit comments

Comments
 (0)