当前位置:网站首页>【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]
}

边栏推荐
- Etcd introduction
- National multi-year solar radiation spatial distribution data 1981-2022, temperature distribution data, evapotranspiration data, evaporation data, rainfall distribution data, sunshine data, wind speed
- Dominating set, independent set, covering set
- 浙大联合微软亚研院发布视频识别新方法,可对视频逐帧识别且无需,数据标记,或可用于手语翻译等
- arguments. Callee implement function recursive call
- Where is it safer to open an account for soda ash futures? How much does it cost to buy soda ash futures?
- msf cs openssl流量加密
- 读取geo表达矩阵
- C# 在PDF文档中应用多种不同字体
- Let WordPress support registered users to upload custom avatars
猜你喜欢

National multi-year solar radiation spatial distribution data 1981-2022, temperature distribution data, evapotranspiration data, evaporation data, rainfall distribution data, sunshine data, wind speed

ELK - X-Pack设置用户密码

再不刷题就晚了,最全的BAT大厂面试题整理
![my. Binlog startup failure caused by the difference between [mysql] and [mysqld] in CNF](/img/bd/a28e74654c7821b3a9cd9260d2e399.png)
my. Binlog startup failure caused by the difference between [mysql] and [mysqld] in CNF

Adapter mode -- can you talk well?

C# 设置或验证 PDF中的文本域格式

吊打面试官,涨姿势

Jest unit test description config json

Intl.NumberFormat 设置数字格式

软件项目管理 7.1.项目进度基本概念
随机推荐
实用WordPress插件收集(更新中)
Is it safe for Xiaobai to open an account directly on the flush?
JS to realize the rotation chart (riding light). Pictures can be switched left and right. Moving the mouse will stop the rotation
[file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)
[go] interpretation of gin source code
Smart sidebar plug-in: Mo widgets
arguments.callee 实现函数递归调用
2020-07 study notes sorting
Hamiltonian graph
Node连接MySql数据库写模糊查询接口
Elk - elastalert largest pit
灵动边栏(Widget)插件:MO Widgets
Gerber文件在PCB制造中的作用
Uncaught typeerror: cannot set property 'next' of undefined
JS interview questions - arrow function, find and filter some and every
Uncaught TypeError: Cannot set property ‘next‘ of undefined 报错解决
Liufan, CFO of papaya mobile, unleashes women's innovative power in the digital age
WordPress数据库缓存插件:DB Cache Reloaded
WordPress landing page customization plug-in recommendation
WordPress user name modification plug-in: username changer