Skip to content

Commit

Permalink
add 1431
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed May 4, 2020
1 parent ce8b21c commit ddf5a03
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
|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|
11 changes: 11 additions & 0 deletions src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public:
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
vector<bool> res;
int m = *max_element(candies.begin(), candies.end());
for (int i : candies) {
res.emplace_back(extraCandies + i >= m);
}
return res;
}
};
19 changes: 19 additions & 0 deletions src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.go
Original file line number Diff line number Diff line change
@@ -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
}
Empty file.
9 changes: 9 additions & 0 deletions src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.js
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 4 additions & 0 deletions src/1431-Kids-With-the-Greatest-Number-of-Candies/1431.py
Original file line number Diff line number Diff line change
@@ -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]
8 changes: 4 additions & 4 deletions src/addProb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']


Expand Down

0 comments on commit ddf5a03

Please sign in to comment.