Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8e59d0

Browse files
✨update: Modify 494
1 parent 20e6e01 commit d8e59d0

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

‎Index/字典树.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| [208. 实现 Trie (前缀树)](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/implement-trie-prefix-tree/solution/gong-shui-san-xie-yi-ti-shuang-jie-er-we-esm9/) | 中等 | 🤩🤩🤩🤩🤩 |
44
| [211. 添加与搜索单词 - 数据结构设计](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/solution/gong-shui-san-xie-yi-ti-shuang-jie-er-we-un94/) | 中等 | 🤩🤩🤩🤩🤩 |
55
| [212. 单词搜索 II](https://leetcode-cn.com/problems/word-search-ii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/word-search-ii/solution/gong-shui-san-xie-yi-ti-shuang-jie-hui-s-am8f/) | 困难 | 🤩🤩🤩🤩 |
6+
| [421. 数组中两个数的最大异或值](https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-bmjdg/) | 中等 | 🤩🤩🤩🤩 |
67
| [677. 键值映射](https://leetcode-cn.com/problems/map-sum-pairs/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/map-sum-pairs/solution/gong-shui-san-xie-jie-he-dfs-de-trie-yun-i4xa/) | 中等 | 🤩🤩🤩🤩 |
78
| [1707. 与数组中元素的最大异或值](https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-xor-with-an-element-from-array/solution/gong-shui-san-xie-jie-zhe-ge-wen-ti-lai-lypqr/) | 困难 | 🤩🤩🤩 |
89

‎Index/贪心算法.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| [11. 盛最多水的容器 ](https://leetcode-cn.com/problems/container-with-most-water/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/container-with-most-water/solution/shua-chuan-lc-shuang-zhi-zhen-tan-xin-ji-52gf/) | 中等 | 🤩🤩🤩🤩🤩 |
44
| [45. 跳跃游戏 II](https://leetcode-cn.com/problems/jump-game-ii/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/jump-game-ii/solution/xiang-jie-dp-tan-xin-shuang-zhi-zhen-jie-roh4/) | 中等 | 🤩🤩🤩🤩 |
55
| [179. 最大数](https://leetcode-cn.com/problems/largest-number/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/largest-number/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-vn86e/) | 中等 | 🤩🤩🤩🤩 |
6+
| [421. 数组中两个数的最大异或值](https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-bmjdg/) | 中等 | 🤩🤩🤩🤩 |
67
| [502. IPO](https://leetcode-cn.com/problems/ipo/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/ipo/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-fk1ra/) | 困难 | 🤩🤩🤩 |
78
| [517. 超级洗衣机](https://leetcode-cn.com/problems/super-washing-machines/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/super-washing-machines/solution/gong-shui-san-xie-noxiang-xin-ke-xue-xi-mzqia/) | 困难 | 🤩🤩🤩 |
89
| [524. 通过删除字母匹配到字典里最长单词](https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/longest-word-in-dictionary-through-deleting/solution/gong-shui-san-xie-xiang-jie-pai-xu-shuan-qi20/) | 中等 | 🤩🤩🤩🤩 |

‎LeetCode/491-500/494. 目标和(中等).md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Tag : 「DFS」、「记忆化搜索」、「背包 DP」、「01 背包」
4747
而 DFS 有「使用全局变量维护」和「接收返回值处理」两种形式。
4848

4949
代码:
50-
```Java []
50+
```Java
5151
class Solution {
5252
public int findTargetSumWays(int[] nums, int t) {
5353
return dfs(nums, t, 0, 0);
@@ -62,7 +62,9 @@ class Solution {
6262
}
6363
}
6464
```
65-
```Java []
65+
66+
67+
```Java
6668
class Solution {
6769
int ans = 0;
6870
public int findTargetSumWays(int[] nums, int t) {
@@ -93,7 +95,7 @@ class Solution {
9395
以上分析都在 [(题解)403. 青蛙过河](https://leetcode-cn.com/problems/frog-jump/solution/gong-shui-san-xie-yi-ti-duo-jie-jiang-di-74fw/) 完整讲过。
9496

9597
代码:
96-
```Java []
98+
```Java
9799
class Solution {
98100
public int findTargetSumWays(int[] nums, int t) {
99101
return dfs(nums, t, 0, 0);
@@ -144,13 +146,13 @@ $$f[i][j] = f[i - 1][j - nums[i - 1]] + f[i - 1][j + nums[i - 1]]$$
144146
因此,我们可以确定动规数组的大小。**同时在转移时,对第二维度的使用做一个 `s` 的右偏移,以确保「负权值」也能够被合理计算/存储。**
145147

146148
代码:
147-
```Java []
149+
```Java
148150
class Solution {
149151
public int findTargetSumWays(int[] nums, int t) {
150152
int n = nums.length;
151153
int s = 0;
152154
for (int i : nums) s += Math.abs(i);
153-
if (t > s) return 0;
155+
if (Math.abs(t) > s) return 0;
154156
int[][] f = new int[n + 1][2 * s + 1];
155157
f[0][0 + s] = 1;
156158
for (int i = 1; i <= n; i++) {
@@ -204,7 +206,7 @@ $$m = \frac{s - target}{2}$$
204206
$$f[i][j] = f[i - 1][j] + f[i - 1][j - nums[i - 1]]$$
205207

206208
代码:
207-
```Java []
209+
```Java
208210
class Solution {
209211
public int findTargetSumWays(int[] nums, int t) {
210212
int n = nums.length;
@@ -232,7 +234,7 @@ class Solution {
232234

233235
### 最后
234236

235-
这是我们「刷穿 LeetCode」系列文章的第 `No.494` 篇,系列开始于 2021年01月01日,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先将所有不带锁的题目刷完
237+
这是我们「刷穿 LeetCode」系列文章的第 `No.494` 篇,系列开始于 2021年01月01日,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完
236238

237239
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
238240

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /