-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Updated solution for 1307 and added solution for 1354. #1823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ef6cff5
Added Solution for 1912. Movie Rental System in python.
nrhitik ca705c1
Update README.md
yanglbme 727bd2c
Update README_EN.md
yanglbme d1241ab
Update Solution.py
yanglbme 5ac39c3
Merge branch 'doocs:main' into main
nrhitik a02c409
Solution for 1900. Earliest and Latest Rounds Where Players Compete.
nrhitik c530b16
Merge branch 'main' into main
nrhitik 24457d6
Merge branch 'main' into main
nrhitik 11ee104
Merge branch 'doocs:main' into main
nrhitik dd85b2c
Added Solution for 1307. Verbal Arithmetic Puzzel and Updated README....
nrhitik cce5b39
Added solution for 1354.
nrhitik 1ba8be6
Merge branch 'main' into main
nrhitik b1d5882
Updated solution for 1307 to pass all the test cases.
nrhitik aa585c8
Merge branch 'main' of https://github.com/nrhitik/leetcode
nrhitik ea51913
Updated README for 1307.
nrhitik 9d9cc9b
Merge branch 'main' into main
nrhitik f06d35e
Merge branch 'main' into main
nrhitik 68821c3
Removed solution for 1307.
nrhitik 00027e9
Merge branch 'main' of https://github.com/nrhitik/leetcode
nrhitik 45b34c5
Merge branch 'main' into main
nrhitik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
solution/1300-1399/1354.Construct Target Array With Multiple Sums/Solution.py
This file contains hidden or 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,23 @@ | ||
class Solution: | ||
def isPossible(self, target: List[int]) -> bool: | ||
if len(target) == 1: | ||
return target[0] == 1 | ||
|
||
summ = sum(target) | ||
maxHeap = [-num for num in target] | ||
heapq.heapify(maxHeap) | ||
|
||
while -maxHeap[0] > 1: | ||
maxi = -heapq.heappop(maxHeap) | ||
restSum = summ - maxi | ||
# Only occurs if n == 2. | ||
if restSum == 1: | ||
return True | ||
updated = maxi % restSum | ||
# Updated == 0 (invalid) or didn't change. | ||
if updated == 0 or updated == maxi: | ||
return False | ||
heapq.heappush(maxHeap, -updated) | ||
summ = summ - maxi + updated | ||
|
||
return True |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.