diff --git a/README.md b/README.md index dec7d1de..3766e78a 100644 --- a/README.md +++ b/README.md @@ -719,4 +719,5 @@ LeetCode |1422|[Maximum Score After Splitting a String](https://leetcode.com/problems/maximum-score-after-splitting-a-string/)|c|[c++](./src/1422-Maximum-Score-After-Splitting-a-String/1422.cpp)|[python](./src/1422-Maximum-Score-After-Splitting-a-String/1422.py)|[go](./src/1422-Maximum-Score-After-Splitting-a-String/1422.go)|[js](./src/1422-Maximum-Score-After-Splitting-a-String/1422.js)|[java](./src/1422-Maximum-Score-After-Splitting-a-String/1422.java)|Easy| |1423|[Maximum Points You Can Obtain from Cards](https://leetcode.com/problems/maximum-points-you-can-obtain-from-cards/)|c|[c++](./src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.cpp)|[python](./src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.py)|[go](./src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.go)|[js](./src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.js)|[java](./src/1423-Maximum-Points-You-Can-Obtain-from-Cards/1423.java)|Medium| |1424|[Diagonal Traverse II](https://leetcode.com/problems/diagonal-traverse-ii/)|c|[c++](./src/1424-Diagonal-Traverse-II/1424.cpp)|[python](./src/1424-Diagonal-Traverse-II/1424.py)|[go](./src/1424-Diagonal-Traverse-II/1424.go)|[js](./src/1424-Diagonal-Traverse-II/1424.js)|[java](./src/1424-Diagonal-Traverse-II/1424.java)|Medium| -|1425|[Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum/)|c|[c++](./src/1425-Constrained-Subsequence-Sum/1425.cpp)|[python](./src/1425-Constrained-Subsequence-Sum/1425.py)|[go](./src/1425-Constrained-Subsequence-Sum/1425.go)|[js](./src/1425-Constrained-Subsequence-Sum/1425.js)|[java](./src/1425-Constrained-Subsequence-Sum/1425.java)|Hard| \ No newline at end of file +|1425|[Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum/)|c|[c++](./src/1425-Constrained-Subsequence-Sum/1425.cpp)|[python](./src/1425-Constrained-Subsequence-Sum/1425.py)|[go](./src/1425-Constrained-Subsequence-Sum/1425.go)|[js](./src/1425-Constrained-Subsequence-Sum/1425.js)|[java](./src/1425-Constrained-Subsequence-Sum/1425.java)|Hard| +|1431|[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)|c|[c++](./src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.cpp)|[python](./src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.py)|[go](./src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.go)|[js](./src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.js)|[java](./src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.java)|Easy| \ No newline at end of file diff --git a/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.cpp b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.cpp new file mode 100644 index 00000000..09dd5c9f --- /dev/null +++ b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.cpp @@ -0,0 +1,11 @@ +class Solution { +public: + vector kidsWithCandies(vector& candies, int extraCandies) { + vector res; + int m = *max_element(candies.begin(), candies.end()); + for (int i : candies) { + res.emplace_back(extraCandies + i >= m); + } + return res; + } +}; \ No newline at end of file diff --git a/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.go b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.go new file mode 100644 index 00000000..7162538d --- /dev/null +++ b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.go @@ -0,0 +1,19 @@ +func kidsWithCandies(candies []int, extraCandies int) []bool { + m := 0 + res := []bool{} + for _, i := range candies { + m = max(m, i) + } + + for _, i := range candies { + res = append(res, extraCandies + i >= m) + } + return res +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} \ No newline at end of file diff --git a/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.java b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.java new file mode 100644 index 00000000..e69de29b diff --git a/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.js b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.js new file mode 100644 index 00000000..b502f1c7 --- /dev/null +++ b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.js @@ -0,0 +1,9 @@ +var kidsWithCandies = function(candies, extraCandies) { + let m = 0, res = []; + for (let i of candies) m = Math.max(m, i); + + for (let i of candies) { + res.push(extraCandies + i >= m); + } + return res; +}; \ No newline at end of file diff --git a/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.py b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.py new file mode 100644 index 00000000..051f6bb9 --- /dev/null +++ b/src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.py @@ -0,0 +1,4 @@ +class Solution: + def kidsWithCandies(self, candies: List[int], extraCandies: int) -> List[bool]: + m = max(candies) + return [i + extraCandies >= m for i in candies] \ No newline at end of file diff --git a/src/addProb.py b/src/addProb.py index cb075056..57861097 100644 --- a/src/addProb.py +++ b/src/addProb.py @@ -2,10 +2,10 @@ import os, bisect # 题目名称 -name = "Constrained Subsequence Sum" -ID = 1425 -url = "https://leetcode.com/problems/constrained-subsequence-sum/" -difficult = "Hard" +name = "Kids With the Greatest Number of Candies" +ID = 1431 +url = "https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/" +difficult = "Easy" prog = ['c', 'cpp', 'py', 'go', 'js', 'java']