-
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
1 parent
02e538c
commit 73211ec
Showing
1 changed file
with
28 additions
and
0 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,28 @@ | ||
/* | ||
* @lc app=leetcode.cn id=1711 lang=golang | ||
* | ||
* [1711] 大餐计数 | ||
*/ | ||
|
||
// @lc code=start | ||
func countPairs(deliciousness []int) int { | ||
var maxVal = deliciousness[0] | ||
for _, v := range deliciousness[1:] { | ||
if v > maxVal { | ||
maxVal = v | ||
} | ||
} | ||
maxSum := maxVal * 2 | ||
var ans int | ||
var cnt = map[int]int{} | ||
for _, v := range deliciousness { | ||
for sum := 1; sum <= maxSum; sum <<= 1 { | ||
ans += cnt[sum-v] | ||
} | ||
cnt[v]++ | ||
} | ||
return ans % (1e9 + 7) | ||
} | ||
|
||
// @lc code=end | ||
|