forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from doocs:main #219
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
05ecea3
style: update desciption to lc problem: No.0003 (#969)
thinkasany d19e4e4
feat: add solutions to lc problem: No.1040
yanglbme 3531802
feat: add solutions to lc problems: No.1041
thinkasany e14f8a8
feat: add solutions to lc problems: No.1040
thinkasany 8cc9aa2
feat: update solutions to lc problems: No.0006
thinkasany 8c7e7a2
style: update desciption to lc problem: No.33
thinkasany 4a27e7b
style: update desciption to lc problem: No.34
thinkasany 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
feat: add solutions to lc problems: No.1040
- Loading branch information
commit e14f8a8e5402cf7ad808f65e183b10f4ff1b39a5
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
19 changes: 19 additions & 0 deletions
solution/1000-1099/1040.Moving Stones Until Consecutive II/Solution.ts
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,19 @@ | ||
function numMovesStonesII(stones: number[]): number[] { | ||
stones.sort((a, b) => a - b); | ||
const n = stones.length; | ||
let mi = n; | ||
const mx = | ||
Math.max(stones[n - 1] - stones[1] + 1, stones[n - 2] - stones[0] + 1) - | ||
(n - 1); | ||
for (let i = 0, j = 0; j < n; ++j) { | ||
while (stones[j] - stones[i] + 1 > n) { | ||
++i; | ||
} | ||
if (j - i + 1 === n - 1 && stones[j] - stones[i] === n - 2) { | ||
mi = Math.min(mi, 2); | ||
} else { | ||
mi = Math.min(mi, n - (j - i + 1)); | ||
} | ||
} | ||
return [mi, mx]; | ||
} |
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.