mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Merge branch 'master' of github.com:youngyangyang04/leetcode-master
This commit is contained in:
@ -131,7 +131,7 @@
|
||||
1. [数组过于简单,但你该了解这些!](./problems/数组理论基础.md)
|
||||
2. [数组:二分查找](./problems/0704.二分查找.md)
|
||||
3. [数组:移除元素](./problems/0027.移除元素.md)
|
||||
4. [数组:序数组的平方](./problems/0977.有序数组的平方.md)
|
||||
4. [数组:有序数组的平方](./problems/0977.有序数组的平方.md)
|
||||
5. [数组:长度最小的子数组](./problems/0209.长度最小的子数组.md)
|
||||
6. [数组:螺旋矩阵II](./problems/0059.螺旋矩阵II.md)
|
||||
7. [数组:总结篇](./problems/数组总结篇.md)
|
||||
|
BIN
problems/.DS_Store
vendored
Normal file
BIN
problems/.DS_Store
vendored
Normal file
Binary file not shown.
@ -174,9 +174,11 @@ next数组就是一个前缀表(prefix table)。
|
||||
长度为前1个字符的子串`a`,最长相同前后缀的长度为0。(注意字符串的**前缀是指不包含最后一个字符的所有以第一个字符开头的连续子串**;**后缀是指不包含第一个字符的所有以最后一个字符结尾的连续子串**。)
|
||||
|
||||
<img src='https://code-thinking.cdn.bcebos.com/pics/KMP%E7%B2%BE%E8%AE%B26.png' width=600 alt='KMP精讲6'> </img></div>
|
||||
|
||||
长度为前2个字符的子串`aa`,最长相同前后缀的长度为1。
|
||||
|
||||
<img src='https://code-thinking.cdn.bcebos.com/pics/KMP%E7%B2%BE%E8%AE%B27.png' width=600 alt='KMP精讲7'> </img></div>
|
||||
|
||||
长度为前3个字符的子串`aab`,最长相同前后缀的长度为0。
|
||||
|
||||
以此类推:
|
||||
|
@ -270,6 +270,8 @@ class Solution {
|
||||
public int findTargetSumWays(int[] nums, int target) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < nums.length; i++) sum += nums[i];
|
||||
//如果target过大 sum将无法满足
|
||||
if ( target < 0 && sum < -target) return 0;
|
||||
if ((target + sum) % 2 != 0) return 0;
|
||||
int size = (target + sum) / 2;
|
||||
if(size < 0) size = -size;
|
||||
|
@ -95,6 +95,8 @@ dp[j] 就是所有的dp[j - coins[i]](考虑coins[i]的情况)相加。
|
||||
|
||||
下标非0的dp[j]初始化为0,这样累计加dp[j - coins[i]]的时候才不会影响真正的dp[j]
|
||||
|
||||
dp[0]=1还说明了一种情况:如果正好选了coins[i]后,也就是j-coins[i] == 0的情况表示这个硬币刚好能选,此时dp[0]为1表示只选coins[i]存在这样的一种选法。
|
||||
|
||||
4. 确定遍历顺序
|
||||
|
||||
本题中我们是外层for循环遍历物品(钱币),内层for遍历背包(金钱总额),还是外层for遍历背包(金钱总额),内层for循环遍历物品(钱币)呢?
|
||||
@ -316,3 +318,4 @@ object Solution {
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||
</a>
|
||||
|
||||
|
Reference in New Issue
Block a user