当前位置:网站首页>Leetcode 115. different subsequences
Leetcode 115. different subsequences
2022-07-25 06:46:00 【Zero if】
Leetcode 115. Different subsequences
Topic linking
subject : Given a string s And a string t , Calculated at s In the subsequence of t Number of occurrences .
One of the strings Subsequence Refer to , By deleting some ( It can also be done without deleting ) Character and does not interfere with the relative position of the remaining characters of the new string .( for example ,“ACE” yes “ABCDE” A subsequence of , and “AEC” No )
The data of the questions ensure that the answers are in line with 32 Bit signed integer range .
Insert a code chip here
Input :s = "rabbbit", t = "rabbit"
Output :3
explain :
As shown in the figure below , Yes 3 Species can be obtained from s Get in "rabbit" The plan .
( Up arrow sign ^ Indicates the selected letter )
rabbbit
^^^^ ^^
rabbbit
^^ ^^^^
rabbbit
^^^ ^^^
The solution is on the official website , Here is just a record of personal problems
Q1: Why is it dp[0][0] Time is the answer ?
A1: There is a key sentence in the solution :
Create a 2D array dp, among dp[i][j] It means that s[i:] In the subsequence of t[j:] Number of occurrences .
In the above expression ,s[i:] Express s From the subscript ii Substring to the end ,t[j:] Express t From the subscript j Substring to the end .
So when i=0,j=0 when , It means from s First character s[0] To end character s[m-1] In the subsequence of t[0] To t[n-1]( String character t) Number of occurrences .
Q2: Why? s[i] And t[j] Consider two aspects when equal ?s[i]=t[j] But what does mismatch mean ?
A2: When equal , You need to judge each t Whether the characters in are equal to s The characters in , When there is no match ,dp[i][j] = dp[i+1][j] It means if it doesn't match ,t[j] remain unchanged , Move s[i], This is the same as that in the title Subsequence Refer to , By deleting some ( It can also be done without deleting ) Character and does not interfere with the relative position of the remaining characters of the new string . Corresponding .
Finally, you can write questions , Don't forget to turn up the array , Or you'll cross the line .
Not necessarily right , If there are mistakes, you are welcome to point them out !
边栏推荐
- Leetcode46 Full Permutation (Introduction to backtracking)
- 【Jailhouse 文章】Base Architectures for virtual-physical computing(2018)
- MySQL queries the table name under the current database
- DOM events
- [Yugong series] July 2022 go teaching course 015 assignment operators and relational operators of operators
- [Yugong series] July 2022 go teaching course 016 logical operators and other operators of operators
- Save the sqoop run template
- 【知识总结】分块和值域分块
- 在C# WinForms应用程序中安装,配置和使用MetroFramework
- Insight into mobile application operation growth in 2022 white paper: the way to "break the situation" in the era of diminishing traffic dividends
猜你喜欢
![[C language] document processing and operation](/img/d7/3d34401f78399dcd6d571bc0bc84bf.png)
[C language] document processing and operation

In container multicast

Thread 类的基本用法

【每日一题】1184. 公交站间的距离

【剑指Offer】模拟实现atoi

Easy gene chip SEQ analysis method: practical workflow and advanced applications

代码中的软件工程:正则表达式十步通关

【愚公系列】2022年7月 Go教学课程 015-运算符之赋值运算符和关系运算符

Baidu xirang's first yuan universe auction ended, and Chen Danqing's six printmaking works were all sold!

Common mode inductance has been heard many times, but what principle do you really understand?
随机推荐
MySQL queries the table name under the current database
[Yugong series] July 2022 go teaching course 016 logical operators and other operators of operators
Insight into mobile application operation growth in 2022 white paper: the way to "break the situation" in the era of diminishing traffic dividends
Prevention strategy of Chang'an chain Shuanghua transaction
Mlx90640 infrared thermal imager temperature measurement module development notes (I)
机器人工程-教学品质-如何判定
【愚公系列】2022年7月 Go教学课程 016-运算符之逻辑运算符和其他运算符
Quick sort code implementation
C#控件开源库:MetroFramework的下载
Robot engineering - teaching quality - how to judge
What does "TTL" mean in domain name resolution?
A little consideration of strategic mode
C language -c51 compilation warning "* * * warning l1: unresolved external symbol" and extern
不只是日志收集,项目监控工具Sentry的安装、配置、使用
JVM tuning summary -xms -xmx -xmn -xss
Labelme labels different objects, displays different colors and batch conversion
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 link with game glitch (SPFA finds positive and negative links)
Baidu Post Bar crawler gets web pages
Installation and configuration of automatic operation and maintenance management workers ansible
The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market