Skip to content

Commit 4561bcd

Browse files
add 1394
1 parent f9764c1 commit 4561bcd

File tree

7 files changed

+54
-5
lines changed

7 files changed

+54
-5
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -691,4 +691,5 @@ LeetCode
691691
|1389|[Create Target Array in the Given Order](https://leetcode.com/problems/create-target-array-in-the-given-order/)|c|[c++](./src/1389-Create-Target-Array-in-the-Given-Order/1389.cpp)|[python](./src/1389-Create-Target-Array-in-the-Given-Order/1389.py)|[go](./src/1389-Create-Target-Array-in-the-Given-Order/1389.go)|[js](./src/1389-Create-Target-Array-in-the-Given-Order/1389.js)|[java](./src/1389-Create-Target-Array-in-the-Given-Order/1389.java)|Easy|
692692
|1390|[Four Divisors](https://leetcode.com/problems/four-divisors/)|c|[c++](./src/1390-Four-Divisors/1390.cpp)|[python](./src/1390-Four-Divisors/1390.py)|[go](./src/1390-Four-Divisors/1390.go)|[js](./src/1390-Four-Divisors/1390.js)|[java](./src/1390-Four-Divisors/1390.java)|Medium|
693693
|1391|[Check if There is a Valid Path in a Grid](https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid/)|c|[c++](./src/1391-Check-if-There-is-a-Valid-Path-in-a-Grid/1391.cpp)|[python](./src/1391-Check-if-There-is-a-Valid-Path-in-a-Grid/1391.py)|[go](./src/1391-Check-if-There-is-a-Valid-Path-in-a-Grid/1391.go)|[js](./src/1391-Check-if-There-is-a-Valid-Path-in-a-Grid/1391.js)|[java](./src/1391-Check-if-There-is-a-Valid-Path-in-a-Grid/1391.java)|Medium|
694-
|1392|[Longest Happy Prefix](https://leetcode.com/problems/longest-happy-prefix/)|c|[c++](./src/1392-Longest-Happy-Prefix/1392.cpp)|[python](./src/1392-Longest-Happy-Prefix/1392.py)|[go](./src/1392-Longest-Happy-Prefix/1392.go)|[js](./src/1392-Longest-Happy-Prefix/1392.js)|[java](./src/1392-Longest-Happy-Prefix/1392.java)|Hard|
694+
|1392|[Longest Happy Prefix](https://leetcode.com/problems/longest-happy-prefix/)|c|[c++](./src/1392-Longest-Happy-Prefix/1392.cpp)|[python](./src/1392-Longest-Happy-Prefix/1392.py)|[go](./src/1392-Longest-Happy-Prefix/1392.go)|[js](./src/1392-Longest-Happy-Prefix/1392.js)|[java](./src/1392-Longest-Happy-Prefix/1392.java)|Hard|
695+
|1394|[Find Lucky Integer in an Array](https://leetcode.com/problems/find-lucky-integer-in-an-array/)|c|[c++](./src/1394-Find-Lucky-Integer-in-an-Array/1394.cpp)|[python](./src/1394-Find-Lucky-Integer-in-an-Array/1394.py)|[go](./src/1394-Find-Lucky-Integer-in-an-Array/1394.go)|[js](./src/1394-Find-Lucky-Integer-in-an-Array/1394.js)|[java](./src/1394-Find-Lucky-Integer-in-an-Array/1394.java)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int findLucky(vector<int>& arr) {
4+
int cnt[501] = {};
5+
for (int i : arr) cnt[i]++;
6+
7+
for (int i = 500; i; i--) {
8+
if (cnt[i] == i) return i;
9+
}
10+
return -1;
11+
}
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
func findLucky(arr []int) int {
2+
cnt := make([]int, 501)
3+
for _, i := range arr {
4+
cnt[i]++
5+
}
6+
7+
for i := 500; i > 0; i-- {
8+
if cnt[i] == i {
9+
return i
10+
}
11+
}
12+
return -1
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int findLucky(int[] arr) {
3+
int[] cnt = new int[501];
4+
for (int i : arr) cnt[i]++;
5+
6+
for (int i = 500; i > 0; i--) {
7+
if (cnt[i] == i) return i;
8+
}
9+
return -1;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var findLucky = function(arr) {
2+
let cnt = new Array(501).fill(0);
3+
for (let i of arr) cnt[i]++;
4+
5+
for (let i = 500; i > 0; i--) {
6+
if (cnt[i] == i) return i;
7+
}
8+
return -1;
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def findLucky(self, arr: List[int]) -> int:
3+
return max([k for k, v in collections.Counter(arr).items() if k == v] + [-1])

src/addProb.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import os, bisect
33

44
# 题目名称
5-
name = "Short Encoding of Words"
6-
ID = 820
7-
url = "https://leetcode.com/problems/short-encoding-of-words/"
8-
difficult = "Medium"
5+
name = "Find Lucky Integer in an Array"
6+
ID = 1394
7+
url = "https://leetcode.com/problems/find-lucky-integer-in-an-array/"
8+
difficult = "Easy"
99
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']
1010

1111

0 commit comments

Comments
 (0)