这里有一堆物资待分配,物资总数量不超过200(),每件物资重量不超过100()。 请问是否可以将这堆物资分配给两个队伍,使得两个队伍的全部的物资重量和相等。
示例1
输入
[1, 5, 11, 5]
输出
true
说明
数组可以分为 [1, 5, 5] 和 [11]
示例2
输入
[1, 2, 3, 5]
输出
false
加载中...
import java.util.*; public class Solution { /** * * @param nums int整型一维数组 * @return bool布尔型 */ public boolean canPartition (int[] nums) { // write code here } }
class Solution { public: /** * * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @return bool布尔型 */ bool canPartition(int* nums, int numsLen) { // write code here } };
# # # @param nums int整型一维数组 # @return bool布尔型 # class Solution: def canPartition(self , nums ): # write code here
/** * * @param nums int整型一维数组 * @return bool布尔型 */ function canPartition( nums ) { // write code here } module.exports = { canPartition : canPartition };
# # # @param nums int整型一维数组 # @return bool布尔型 # class Solution: def canPartition(self , nums ): # write code here
package main /** * * @param nums int整型一维数组 * @return bool布尔型 */ func canPartition( nums []int ) bool { // write code here }
/** * * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @return bool布尔型 */ bool canPartition(int* nums, int numsLen ) { // write code here }
[1, 5, 11, 5]
true
[1, 2, 3, 5]
false