牛牛是一种非常特殊的动物,不同种群的牛有着不同的特征值。现在给定不同种群的牛的特征值 features 和一个目标特征值 target。编写一个函数来计算可以组合出目标特征值所需的最少的动物牛个数。如果无法组合出目标特征值,返回 -1。
示例1
输入
[1, 2, 5],11
输出
3
示例2
输入
[2],5
输出
-1
备注:
1 1 0
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ public int minAnimalCount (int[] features, int target) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型vector * @param target int整型 * @return int整型 */ int minAnimalCount(vector
& features, int target) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param features int整型一维数组 # @param target int整型 # @return int整型 # class Solution: def minAnimalCount(self , features , target ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ public int minAnimalCount (List
features, int target) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ function minAnimalCount( features , target ) { // write code here } module.exports = { minAnimalCount : minAnimalCount };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param features int整型一维数组 # @param target int整型 # @return int整型 # class Solution: def minAnimalCount(self , features: List[int], target: int) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ func minAnimalCount( features []int , target int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param featuresLen int features数组长度 * @param target int整型 * @return int整型 */ int minAnimalCount(int* features, int featuresLen, int target ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param features int整型一维数组 # @param target int整型 # @return int整型 # class Solution def minAnimalCount(features, target) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ def minAnimalCount(features: Array[Int],target: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ fun minAnimalCount(features: IntArray,target: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ public int minAnimalCount (int[] features, int target) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ export function minAnimalCount(features: number[], target: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ func minAnimalCount ( _ features: [Int], _ target: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param features int整型一维数组 * @param target int整型 * @return int整型 */ pub fn minAnimalCount(&self, features: Vec
, target: i32) -> i32 { // write code here } }
[1, 2, 5],11
3
[2],5
-1