设计模式 - 桥接模式
Leetcode - Maximum Width of Binary Tree

Leetcode - 3Sum With Multiplicity

violet posted @ Jul 09, 2020 12:59:39 AM in 算法 with tags Algorithm Golang 3sum , 222 阅读

https://leetcode.com/problems/3sum-with-multiplicity/

Given an integer array A, and an integer target, return the number of tuples i, j, k  such that i < j < k and A[i] + A[j] + A[k] == target.

As the answer can be very large, return it modulo 10^9 + 7.

 

Example 1:

Input: A = [1,1,2,2,3,3,4,4,5,5], target = 8
Output: 20
Explanation: 
Enumerating by the values (A[i], A[j], A[k]):
(1, 2, 5) occurs 8 times;
(1, 3, 4) occurs 8 times;
(2, 2, 4) occurs 2 times;
(2, 3, 3) occurs 2 times.
func threeSumMulti(A []int, target int) int {
    hash := map[int]int{}
    result := 0
    mod := 1000000007
    for i := 0; i < len(A); i++ {
        if v, ok := hash[target - A[i]]; ok {
            result = (result + v) % mod
        }
        for j := 0; j < i; j++ {
            tmp := A[i] + A[j]
            hash[tmp]++
        }
    }
    return result
}
international roamin 说:
Feb 06, 2023 08:02:46 AM

According to TRAI rules, operators do not provide International Roaming services by default; therefore, when a customer requires the facility in a BSNL prepaid SIM card, he or she must approach the nearest customer service center for a BSNL SIM replacement with a new unpaired SIM that supports international roaming, international roaming BSNL known as a BSNL DUAL IMSI International roaming SIM, and then, after activating the duplicate SIM, the mobile user must recharge with the below-mentioned pack for successful activation


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter