农场里有一群奶牛,每头奶牛都有自己的体重。农场主想把奶牛分成三组,使得三组奶牛的体重和相等。你能帮他完成这个任务吗?
示例1
输入
[10,20,30,30]
输出
true
说明
可以将奶牛分成三组,每组的体重是[30]。
示例2
输入
[10,20,30,40]
输出
false
备注:
1 1
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ public boolean canPartitionII (int[] weights) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型vector * @return bool布尔型 */ bool canPartitionII(vector
& weights) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param weights int整型一维数组 # @return bool布尔型 # class Solution: def canPartitionII(self , weights ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ public bool canPartitionII (List
weights) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ function canPartitionII( weights ) { // write code here } module.exports = { canPartitionII : canPartitionII };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param weights int整型一维数组 # @return bool布尔型 # class Solution: def canPartitionII(self , weights: List[int]) -> bool: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ func canPartitionII( weights []int ) bool { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @param weightsLen int weights数组长度 * @return bool布尔型 */ bool canPartitionII(int* weights, int weightsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param weights int整型一维数组 # @return bool布尔型 # class Solution def canPartitionII(weights) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ def canPartitionII(weights: Array[Int]): Boolean = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ fun canPartitionII(weights: IntArray): Boolean { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ public boolean canPartitionII (int[] weights) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ export function canPartitionII(weights: number[]): boolean { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ func canPartitionII ( _ weights: [Int]) -> Bool { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param weights int整型一维数组 * @return bool布尔型 */ pub fn canPartitionII(&self, weights: Vec
) -> bool { // write code here } }
[10,20,30,30]
true
[10,20,30,40]
false