Skip to content

Commit 771f3a9

Browse files
committedApr 7, 2020
add 1402
1 parent cb59dd6 commit 771f3a9

File tree

7 files changed

+60
-5
lines changed

7 files changed

+60
-5
lines changed
 

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -698,4 +698,5 @@ LeetCode
698698
|1397|[Find All Good Strings](https://leetcode.com/problems/find-all-good-strings/)|c|[c++](./src/1397-Find-All-Good-Strings/1397.cpp)|[python](./src/1397-Find-All-Good-Strings/1397.py)|[go](./src/1397-Find-All-Good-Strings/1397.go)|[js](./src/1397-Find-All-Good-Strings/1397.js)|[java](./src/1397-Find-All-Good-Strings/1397.java)|Hard|
699699
|1399|[Count Largest Group](https://leetcode.com/problems/count-largest-group/)|c|[c++](./src/1399-Count-Largest-Group/1399.cpp)|[python](./src/1399-Count-Largest-Group/1399.py)|[go](./src/1399-Count-Largest-Group/1399.go)|[js](./src/1399-Count-Largest-Group/1399.js)|[java](./src/1399-Count-Largest-Group/1399.java)|Easy|
700700
|1400|[Construct K Palindrome Strings](https://leetcode.com/problems/construct-k-palindrome-strings/)|c|[c++](./src/1400-Construct-K-Palindrome-Strings/1400.cpp)|[python](./src/1400-Construct-K-Palindrome-Strings/1400.py)|[go](./src/1400-Construct-K-Palindrome-Strings/1400.go)|[js](./src/1400-Construct-K-Palindrome-Strings/1400.js)|[java](./src/1400-Construct-K-Palindrome-Strings/1400.java)|Medium|
701-
|1401|[Circle and Rectangle Overlapping](https://leetcode.com/problems/circle-and-rectangle-overlapping/)|c|[c++](./src/1401-Circle-and-Rectangle-Overlapping/1401.cpp)|[python](./src/1401-Circle-and-Rectangle-Overlapping/1401.py)|[go](./src/1401-Circle-and-Rectangle-Overlapping/1401.go)|[js](./src/1401-Circle-and-Rectangle-Overlapping/1401.js)|[java](./src/1401-Circle-and-Rectangle-Overlapping/1401.java)|Medium|
701+
|1401|[Circle and Rectangle Overlapping](https://leetcode.com/problems/circle-and-rectangle-overlapping/)|c|[c++](./src/1401-Circle-and-Rectangle-Overlapping/1401.cpp)|[python](./src/1401-Circle-and-Rectangle-Overlapping/1401.py)|[go](./src/1401-Circle-and-Rectangle-Overlapping/1401.go)|[js](./src/1401-Circle-and-Rectangle-Overlapping/1401.js)|[java](./src/1401-Circle-and-Rectangle-Overlapping/1401.java)|Medium|
702+
|1402|[Reducing Dishes](https://leetcode.com/problems/reducing-dishes/)|c|[c++](./src/1402-Reducing-Dishes/1402.cpp)|[python](./src/1402-Reducing-Dishes/1402.py)|[go](./src/1402-Reducing-Dishes/1402.go)|[js](./src/1402-Reducing-Dishes/1402.js)|[java](./src/1402-Reducing-Dishes/1402.java)|Hard|

‎src/1402-Reducing-Dishes/1402.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int maxSatisfaction(vector<int>& s) {
4+
sort(s.begin(), s.end());
5+
int res = 0, total = 0, n = s.size();
6+
7+
for (int i = n - 1; i >= 0 && s[i] > -total; --i) {
8+
total += s[i];
9+
res += total;
10+
}
11+
return res;
12+
}
13+
};

‎src/1402-Reducing-Dishes/1402.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
func maxSatisfaction(s []int) int {
2+
sort.Ints(s)
3+
res, total, n := 0, 0, len(s)
4+
5+
for i := n - 1; i >= 0 && s[i] > -total; i-- {
6+
total += s[i]
7+
res += total
8+
}
9+
return res
10+
}

‎src/1402-Reducing-Dishes/1402.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int maxSatisfaction(int[] s) {
3+
Arrays.sort(s);
4+
int res = 0, total = 0, n = s.length;
5+
6+
for (int i = n - 1; i >= 0 && s[i] > -total; --i) {
7+
total += s[i];
8+
res += total;
9+
}
10+
return res;
11+
}
12+
}

‎src/1402-Reducing-Dishes/1402.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var maxSatisfaction = function(s) {
2+
s.sort((a, b) => a - b);
3+
let res = 0, total = 0, n = s.length;
4+
5+
for (let i = n - 1; i >= 0 && s[i] > -total; --i) {
6+
total += s[i];
7+
res += total;
8+
}
9+
return res;
10+
};

‎src/1402-Reducing-Dishes/1402.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def maxSatisfaction(self, s: List[int]) -> int:
3+
res = total = 0
4+
s.sort()
5+
6+
while s and s[-1] + total > 0:
7+
total += s.pop()
8+
res += total
9+
return res

‎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 = "Circle and Rectangle Overlapping"
6-
ID = 1401
7-
url = "https://leetcode.com/problems/circle-and-rectangle-overlapping/"
8-
difficult = "Medium"
5+
name = "Reducing Dishes"
6+
ID = 1402
7+
url = "https://leetcode.com/problems/reducing-dishes/"
8+
difficult = "Hard"
99
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']
1010

1111

0 commit comments

Comments
 (0)