Skip to content

Commit

Permalink
add 1403
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Apr 7, 2020
1 parent 771f3a9 commit cac187e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,4 +699,5 @@ LeetCode
|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|
|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|
|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|
|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|
|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|
|1403|[Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/)|c|[c++](./src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.cpp)|[python](./src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.py)|[go](./src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.go)|[js](./src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.js)|[java](./src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.java)|Easy|
15 changes: 15 additions & 0 deletions src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
vector<int> minSubsequence(vector<int>& nums) {
sort(nums.begin(), nums.end());
vector<int> res;
int cur = 0, t = accumulate(nums.begin(), nums.end(), 0) / 2;

for (int i = nums.size() - 1; ~i; i--) {
cur += nums[i];
res.emplace_back(nums[i]);
if (cur > t) return res;
}
return res;
}
};
19 changes: 19 additions & 0 deletions src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
func minSubsequence(nums []int) []int {
sort.Ints(nums)
res := make([]int, 0)
cur, t := 0, 0

for _, i := range nums {
t += i
}
t >>= 1

for i := len(nums) - 1; i >= 0; i-- {
cur += nums[i]
res = append(res, nums[i])
if cur > t {
return res
}
}
return res
}
17 changes: 17 additions & 0 deletions src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public List<Integer> minSubsequence(int[] nums) {
Arrays.sort(nums);
List<Integer> res = new ArrayList();
int cur = 0, t = 0;

for (int i : nums) t += i;
t /= 2;

for (int i = nums.length - 1; i >= 0; i--) {
cur += nums[i];
res.add(nums[i]);
if (cur > t) return res;
}
return res;
}
}
14 changes: 14 additions & 0 deletions src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var minSubsequence = function(nums) {
nums.sort((a, b) => a - b);
let res = [], cur = 0, t = 0;

for (let i of nums) t += i;
t >>= 1;

for (let i = nums.length - 1; i >= 0; i--) {
cur += nums[i];
res.push(nums[i]);
if (cur > t) return res;
}
return res;
};
10 changes: 10 additions & 0 deletions src/1403-Minimum-Subsequence-in-Non-Increasing-Order/1403.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def minSubsequence(self, nums: List[int]) -> List[int]:
nums.sort(reverse=True)
res, cur, t = [], 0, sum(nums) / 2

for i in nums:
cur += i
res.append(i)
if cur > t: return res
return res
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 = "Reducing Dishes"
ID = 1402
url = "https://leetcode.com/problems/reducing-dishes/"
difficult = "Hard"
name = "Minimum Subsequence in Non-Increasing Order"
ID = 1403
url = "https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/"
difficult = "Easy"
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']


Expand Down

0 comments on commit cac187e

Please sign in to comment.