-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #882 from 0xff-dev/2491
Add solution and test-cases for problem 2491
- Loading branch information
Showing
3 changed files
with
50 additions
and
22 deletions.
There are no files selected for viewing
38 changes: 25 additions & 13 deletions
38
leetcode/2401-2500/2491.Divide-Players-Into-Teams-of-Equal-Skill/README.md
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
20 changes: 18 additions & 2 deletions
20
leetcode/2401-2500/2491.Divide-Players-Into-Teams-of-Equal-Skill/Solution.go
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,5 +1,21 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
import "sort" | ||
|
||
func Solution(skill []int) int64 { | ||
sort.Ints(skill) | ||
cur := -1 | ||
ans := int64(0) | ||
for s, e := 0, len(skill)-1; s < e; s, e = s+1, e-1 { | ||
if cur == -1 { | ||
cur = skill[s] + skill[e] | ||
ans += int64(skill[s]) * int64(skill[e]) | ||
continue | ||
} | ||
if skill[s]+skill[e] != cur { | ||
return -1 | ||
} | ||
ans += int64(skill[s]) * int64(skill[e]) | ||
} | ||
return ans | ||
} |
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