给你一个数组 candies 和一个整数 candiesNeed ,其中 candies[i] 代表第 i 个孩子拥有的糖果数目,编写一个函数求是否存在两个孩子的糖果数之和等于candiesNeed ,并输出两个孩子的编号。 注意:若存在多种组合,则输出下标较小的。例如满足条件的孩子有0和1、0和2,则输出0和1;满足条件的孩子有0和3、1和2,则输出0和3。
示例1
输入
1,[1,0,1,2]
输出
[0,1]
示例2
输入
1,[0,1,2,3]
输出
[0,1]
示例3
输入
1,[2,3,4,3]
输出
[-1,-1]
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 找到2个孩子的糖果数之和等于指定值 * @param candiesNeed int整型 2个孩子的糖果数之和 * @param candies int整型一维数组 每个孩子的糖果数 * @return int整型一维数组 */ public int[] find_children (int candiesNeed, int[] candies) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 找到2个孩子的糖果数之和等于指定值 * @param candiesNeed int整型 2个孩子的糖果数之和 * @param candies int整型一维数组 每个孩子的糖果数 * @param candiesLen int candies数组长度 * @return int整型vector */ vector
find_children(int candiesNeed, int* candies, int candiesLen) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # 找到2个孩子的糖果数之和等于指定值 # @param candiesNeed int整型 2个孩子的糖果数之和 # @param candies int整型一维数组 每个孩子的糖果数 # @return int整型一维数组 # class Solution: def find_children(self , candiesNeed , candies ): # write code here
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 找到2个孩子的糖果数之和等于指定值 * @param candiesNeed int整型 2个孩子的糖果数之和 * @param candies int整型一维数组 每个孩子的糖果数 * @return int整型一维数组 */ function find_children( candiesNeed , candies ) { // write code here } module.exports = { find_children : find_children };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # 找到2个孩子的糖果数之和等于指定值 # @param candiesNeed int整型 2个孩子的糖果数之和 # @param candies int整型一维数组 每个孩子的糖果数 # @return int整型一维数组 # class Solution: def find_children(self , candiesNeed , candies ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 找到2个孩子的糖果数之和等于指定值 * @param candiesNeed int整型 2个孩子的糖果数之和 * @param candies int整型一维数组 每个孩子的糖果数 * @return int整型一维数组 */ func find_children( candiesNeed int , candies []int ) []int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 找到2个孩子的糖果数之和等于指定值 * @param candiesNeed int整型 2个孩子的糖果数之和 * @param candies int整型一维数组 每个孩子的糖果数 * @param candiesLen int candies数组长度 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ int* find_children(int candiesNeed, int* candies, int candiesLen, int* returnSize ) { // write code here }
1,[1,0,1,2]
[0,1]
1,[0,1,2,3]
[0,1]
1,[2,3,4,3]
[-1,-1]