File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments