Skip to content

Commit 48afed5

Browse files
authored
Merge pull request #1260 from cotijoy/master
366-Week 08
2 parents f4b0589 + 044f63d commit 48afed5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @lc app=leetcode.cn id=115 lang=java
3+
*
4+
* [115] 不同的子序列
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public int numDistinct(String s, String t) {
10+
int[][] dp = new int[t.length() + 1][s.length() + 1];
11+
for (int j = 0; j < s.length() + 1; j++) dp[0][j] = 1;
12+
for (int i = 1; i < t.length() + 1; i++) {
13+
for (int j = 1; j < s.length() + 1; j++) {
14+
if (t.charAt(i - 1) == s.charAt(j - 1)) dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
15+
else dp[i][j] = dp[i][j - 1];
16+
}
17+
}
18+
return dp[t.length()][s.length()];
19+
}
20+
}
21+
// @lc code=end
22+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @lc app=leetcode.cn id=387 lang=java
3+
*
4+
* [387] 字符串中的第一个唯一字符
5+
*/
6+
7+
// @lc code=start
8+
class Solution {
9+
public int firstUniqChar(String s) {
10+
Map<Character, Integer> map = new HashMap<>();
11+
for (int i = 0; i < s.length(); i++) {
12+
map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);
13+
}
14+
for (int i = 0; i < s.length(); i++) {
15+
if (map.get(s.charAt(i)) == 1) {
16+
return i;
17+
}
18+
}
19+
return -1;
20+
}
21+
}
22+
// @lc code=end
23+

0 commit comments

Comments
 (0)