Skip to content

Commit

Permalink
抄题解都只能击败53%???
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerxiong committed Jul 7, 2021
1 parent 02e538c commit 73211ec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 1711.大餐计数.go
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

0 comments on commit 73211ec

Please sign in to comment.