统计三元组
题解
讨论
查看他人的提交
题号:NC211800
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
现在给定一个数组arr,和a,b两个数字,你要做的就是找到(i,j,k)。且满足
1. 0 <= i < j < k < arr.size()
2. |arr[i] - arr[j]| <= a
3. |arr[j] - arr[k]| <= b
统计满足条件的个数并返回(最后结果可能很大,请取1000000007的余数)。
示例1
输入
复制
[7,1,8,9,0],3,3
[7,1,8,9,0],3,3
返回值
复制
1
1
说明
只有(7,8,9)符合要求
备注:
arr.size() <= 5000
其余变量均<=1e9
统计三元组
返回全部题目
列表加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param arr int整型一维数组 * @param a int整型 * @param b int整型 * @return int整型 */ public int countTriplets (int[] arr, int a, int b) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param arr int整型vector * @param a int整型 * @param b int整型 * @return int整型 */ int countTriplets(vector
& arr, int a, int b) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param arr int整型一维数组 # @param a int整型 # @param b int整型 # @return int整型 # class Solution: def countTriplets(self , arr , a , b ): # write code here
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param arr int整型一维数组 * @param a int整型 * @param b int整型 * @return int整型 */ function countTriplets( arr , a , b ) { // write code here } module.exports = { countTriplets : countTriplets };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param arr int整型一维数组 # @param a int整型 # @param b int整型 # @return int整型 # class Solution: def countTriplets(self , arr , a , b ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param arr int整型一维数组 * @param a int整型 * @param b int整型 * @return int整型 */ func countTriplets( arr []int , a int , b int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param arr int整型一维数组 * @param arrLen int arr数组长度 * @param a int整型 * @param b int整型 * @return int整型 */ int countTriplets(int* arr, int arrLen, int a, int b ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param arr int整型一维数组 # @param a int整型 # @param b int整型 # @return int整型 # class Solution def countTriplets(arr, a, b) # write code here end end
[7,1,8,9,0],3,3
1