-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/ | ||
|
||
from typing import List | ||
import unittest | ||
|
||
|
||
class Solution: | ||
def minSubsequence(self, nums: List[int]) -> List[int]: | ||
nums.sort(reverse=True) | ||
|
||
total = sum(nums) | ||
total_result = 0 | ||
result: List[int] = [] | ||
|
||
for n in nums: | ||
result.append(n) | ||
total -= n | ||
total_result += n | ||
|
||
if total_result > total: | ||
return result | ||
|
||
return result | ||
|
||
|
||
class Test(unittest.TestCase): | ||
def setUp(self): | ||
self.solution = Solution() | ||
|
||
def test_first(self): | ||
self.assertEqual(self.solution.minSubsequence(nums=[4, 3, 10, 9, 8]), [10, 9]) | ||
|
||
def test_second(self): | ||
self.assertEqual(self.solution.minSubsequence(nums=[4, 4, 7, 6, 7]), [7, 7, 6]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,63 @@ | ||
| Problem Number | Tag | URL | | ||
| -------------- | ---------------------- | --------------------------------------------------------------------- | | ||
| 1.py | Hash table | https://leetcode.com/problems/two-sum/ | | ||
| 1051.py | | | | ||
| 1207.py | | | | ||
| 1337.py | Heap | https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix | | ||
| 1356.py | | | | ||
| 1365.py | | | | ||
| 1370.py | | | | ||
| 1436.py | | | | ||
| 1464.py | | | | ||
| 1475.py | | | | ||
| 1512.py | | | | ||
| 1636.py | | | | ||
| 1656.py | | | | ||
| 1684.py | | | | ||
| 1710.py | | | | ||
| 1742.py | | | | ||
| 1748.py | | | | ||
| 1832.py | | | | ||
| 1859.py | | | | ||
| 1876.py | | | | ||
| 1920.py | | | | ||
| 1935.py | | | | ||
| 1941.py | | | | ||
| 20.py | | | | ||
| 2006.py | | | | ||
| 2032.py | | | | ||
| 2037.py | | | | ||
| 2053.py | | | | ||
| 2089.py | Sorting, Binary Search | https://leetcode.com/problems/find-target-indices-after-sorting-array | | ||
| 2060.py | | | | ||
| 2103.py | | | | ||
| 2154.py | | | | ||
| 2206.py | | | | ||
| 2215.py | | | | ||
| 2283.py | | | | ||
| 2325.py | | | | ||
| 2341.py | | | | ||
| 2363.py | | | | ||
| 2367-2.py | | | | ||
| 2367.py | | | | ||
| 2418.py | | | | ||
| 2475.py | | | | ||
| 2500.py | | | | ||
| 2545.py | | | | ||
| 2570.py | | | | ||
| 2670.py | | | | ||
| 2716.py | | | | ||
| 2733.py | | | | ||
| 2744.py | | | | ||
| 2848.py | | | | ||
| 2913.py | | | | ||
| 2932.py | | | | ||
| 414.py | | | | ||
| 496.py | | | | ||
| 56.py | | | | ||
| 561.py | | | | ||
| 771.py | | | | ||
| 804.py | | | | ||
| 905.py | | | | ||
| 961.py | | | | ||
| Problem Number | Tag | URL | | ||
| -------------- | ---------------------- | -------------------------------------------------------------------------- | | ||
| 1.py | Hash table | https://leetcode.com/problems/two-sum/ | | ||
| 1051.py | | | | ||
| 1207.py | | | | ||
| 1337.py | Heap | https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix | | ||
| 1356.py | | | | ||
| 1365.py | | | | ||
| 1370.py | | | | ||
| 1406.py | Sorting | https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order/ | | ||
| 1436.py | | | | ||
| 1464.py | | | | ||
| 1475.py | | | | ||
| 1512.py | | | | ||
| 1636.py | | | | ||
| 1656.py | | | | ||
| 1684.py | | | | ||
| 1710.py | | | | ||
| 1742.py | | | | ||
| 1748.py | | | | ||
| 1832.py | | | | ||
| 1859.py | | | | ||
| 1876.py | | | | ||
| 1920.py | | | | ||
| 1935.py | | | | ||
| 1941.py | | | | ||
| 20.py | | | | ||
| 2006.py | | | | ||
| 2032.py | | | | ||
| 2037.py | | | | ||
| 2053.py | | | | ||
| 2089.py | Sorting, Binary Search | https://leetcode.com/problems/find-target-indices-after-sorting-array | | ||
| 2060.py | | | | ||
| 2103.py | | | | ||
| 2154.py | | | | ||
| 2206.py | | | | ||
| 2215.py | | | | ||
| 2283.py | | | | ||
| 2325.py | | | | ||
| 2341.py | | | | ||
| 2363.py | | | | ||
| 2367-2.py | | | | ||
| 2367.py | | | | ||
| 2418.py | | | | ||
| 2475.py | | | | ||
| 2500.py | | | | ||
| 2545.py | | | | ||
| 2570.py | | | | ||
| 2670.py | | | | ||
| 2716.py | | | | ||
| 2733.py | | | | ||
| 2744.py | | | | ||
| 2848.py | | | | ||
| 2913.py | | | | ||
| 2932.py | | | | ||
| 414.py | | | | ||
| 496.py | | | | ||
| 56.py | | | | ||
| 561.py | | | | ||
| 771.py | | | | ||
| 804.py | | | | ||
| 905.py | | | | ||
| 961.py | | | |