Skip to content

Commit ae0ba79

Browse files
committed
:)
1 parent 7afa8a1 commit ae0ba79

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

dynamic programming/package.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#### 有N件物品和一个容量为V的背包。第i件物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使价值总和最大。
2+
背包容积为10,5种物品,
3+
价值->重量
4+
8 6
5+
7 4
6+
4 2
7+
5 4
8+
5 3
9+
```c
10+
#include "stdio.h"
11+
define max(a,b) ((a)>(b)?(a):(b))
12+
13+
main(){
14+
int v = 10;
15+
int n = 5;
16+
17+
int value[] = {0, 8, 7, 4, 5, 5};
18+
int weight[] = {0, 6, 4, 2, 4, 3};
19+
20+
int i, j;
21+
int dp[][];
22+
}
23+
```
File renamed without changes.

dynamic programming/最长公共子序列(LCS).md

Whitespace-only changes.

dynamic programming/最长递增子序列(LIS).md

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

最长不重复子串.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Given "abcabcbb", the answer is "abc", which the length is 3.
2+
Given "bbbbb", the answer is "b", with the length of 1.
3+
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
4+
5+
滑动窗口是数组/字符串问题中常用的抽象概念。窗口是数组/字符串中通常由开始和结束索引定义的元素范围,即[i,j)(左闭合,右开)。滑动窗口是一个窗口,将其两个边界滑动到某个方向。例如,如果我们通过一个元素将[i,j)向右滑动,则它变为[i + 1,j + 1)(左闭右开)。
6+
7+
回到我们的问题。我们使用HashSet将字符存储在当前窗口[i,j)(j = i)。然后我们将索引j向右滑动。如果不在HashSet中,我们会进一步滑动j。这样做直到s[j]已经在HashSet中。在这一点上,我们发现没有重复字符的子字符串的最大大小从索引i开始。重复上面的步骤,我们就能得到我们的答案。
8+
9+
```java
10+
public class Solution {
11+
public int lengthOfLongestSubstring(String s) {
12+
int n = s.length();
13+
Set<Character> set = new HashSet<>();
14+
int ans = 0, i = 0, j = 0;
15+
while (i < n && j < n) {
16+
// try to extend the range [i, j]
17+
if (!set.contains(s.charAt(j))){
18+
set.add(s.charAt(j++));
19+
ans = Math.max(ans, j - i);
20+
}
21+
else {
22+
set.remove(s.charAt(i++));
23+
}
24+
}
25+
return ans;
26+
}
27+
}
28+
```

0 commit comments

Comments
 (0)