当前位置:网站首页>【LeetCode】494. Objective and (2 wrong questions)
【LeetCode】494. Objective and (2 wrong questions)
2022-06-11 11:49:00 【Kaimar】


- Ideas
The first feeling is the law of violence , But it will time out .
Every nums It can only be used once , The object is nums[i], So is the value nums[i], The capacity of the backpack is target, Therefore, it can be analogized as 01 knapsack problem , The tricky thing is to add positive and negative questions .
Refer to the explanation of the question
S Namely target


func sum(nums []int) int {
sum := 0
for _, v := range nums {
sum += v
}
return sum
}
func abs(a int) int {
return int(math.Abs(float64(a)))
}
func findTargetSumWays(nums []int, target int) int {
nums_sum := sum(nums)
if abs(target) > nums_sum {
return 0
}
if (nums_sum + target) % 2 == 1 {
return 0
}
bag := (target + nums_sum) / 2
dp := make([]int, bag + 1)
dp[0] = 1
for i := 0; i < len(nums); i++ {
for j := bag; j >= nums[i]; j-- {
dp[j] += dp[j - nums[i]]
}
}
return dp[bag]
}

边栏推荐
- Guangdong municipal safety construction data management software 2022 new forms are coming
- WordPress database cache plug-in: DB cache Reloaded
- 2019年书单
- C# 在PDF文档中应用多种不同字体
- 实用WordPress插件收集(更新中)
- NFT digital collection app system construction
- Only when you find your own advantages can you work tirelessly and get twice the result with half the effort!
- Command mode - attack, secret weapon
- Intl.numberformat set number format
- [go] interpretation of gin source code
猜你喜欢

CVPR 2022 | 文本引导的实体级别图像操作ManiTrans

How does Sister Feng change to ice?

The application of the spingboot+quartrz production environment supports distributed, custom corn, reflective execution of multiple tasks

Guangdong municipal safety construction data management software 2022 new forms are coming

JS prototype. The find () method has no effect on the object array. It is urgent...

Intl.NumberFormat 设置数字格式

Node连接MySql数据库写模糊查询接口

刷题笔记(十三)--二叉树:前中后序遍历(复习)

CVPR 2022 𞓜 text guided entity level image manipulation manitrans

吊打面试官,涨姿势
随机推荐
The role of Gerber file in PCB manufacturing
[issue 31] 360 background development practice experience - two rounds of technical aspects
灵动边栏(Widget)插件:MO Widgets
普通人应当如何挑选年金险产品?
C# 设置或验证 PDF中的文本域格式
Network protocol of yyds dry goods inventory: datagram socket for detailed explanation of socket protocol
ELK - X-Pack设置用户密码
测试cos-html-cache静态缓存插件
Learning in Bi design 03
2022 | framework for Android interview -- Analysis of the core principles of binder, handler, WMS and AMS!
JS interview questions - arrow function, find and filter some and every
Zhejiang University and Microsoft Asia Research Institute released a new method of video recognition, which can recognize video frame by frame without data marking, or can be used for sign language tr
Smart sidebar plug-in: Mo widgets
Split data - horizontal split and vertical split
Streaking? Baa!
[第二章 基因和染色体的关系]生物知识概括–高一生物
WordPress登录页面定制插件推荐
my.cnf中 [mysql]与[mysqld] 的区别 引起的binlog启动失败的问题
Web development model selection, who graduated from web development
Centos7.x下安装mysql8遇到的问题Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022