-
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 #867 from 0xff-dev/2441
Add solution and test-cases for problem 2441
- Loading branch information
Showing
3 changed files
with
39 additions
and
22 deletions.
There are no files selected for viewing
31 changes: 18 additions & 13 deletions
31
...2401-2500/2441.Largest-Positive-Integer-That-Exists-With-Its-Negative/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
16 changes: 14 additions & 2 deletions
16
leetcode/2401-2500/2441.Largest-Positive-Integer-That-Exists-With-Its-Negative/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,17 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int) int { | ||
e := make(map[int]struct{}) | ||
ans := -1 | ||
for _, n := range nums { | ||
if _, ok := e[-n]; ok { | ||
if n < 0 { | ||
n = -n | ||
} | ||
ans = max(ans, n) | ||
continue | ||
} | ||
e[n] = struct{}{} | ||
} | ||
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