# 判断子序列()-其他

## 判断子序列()

### 一、题目描述

``````输入：s = "abc", t = "ahbgdc"

``````

``````输入：s = "axc", t = "ahbgdc"

``````

### 三、解题方法

``````class Solution {
public boolean isSubsequence(String s, String t) {
int index1 = 0;
int index2 = 0;

for(int i = 0;i<t.length();i++){

if(s.length() == index1){
break;
}

if(s.charAt(index1) == t.charAt(index2)){
index2++;
index1++;
}else{
index2++;
}
}

return index1 == s.length();
}
}
``````

``````class Solution {
public boolean isSubsequence(String s, String t) {
char[] str = new char[s.length()];
int index1 = 0;
int index2 = 0;

for(int i = 0;i<t.length();i++){

if(s.length() == index1){
break;
}

char s1 = s.charAt(index1);
char s2 = t.charAt(index2);

if(s1 == s2){
index2++;
index1++;
}else{
index2++;
}
}

return index1 == s.length();
}
}
``````
————————

### 一、题目描述

``````输入：s = "abc", t = "ahbgdc"

``````

``````输入：s = "axc", t = "ahbgdc"

``````

### 三、解题方法

``````class Solution {
public boolean isSubsequence(String s, String t) {
int index1 = 0;
int index2 = 0;

for(int i = 0;i<t.length();i++){

if(s.length() == index1){
break;
}

if(s.charAt(index1) == t.charAt(index2)){
index2++;
index1++;
}else{
index2++;
}
}

return index1 == s.length();
}
}
``````

``````class Solution {
public boolean isSubsequence(String s, String t) {
char[] str = new char[s.length()];
int index1 = 0;
int index2 = 0;

for(int i = 0;i<t.length();i++){

if(s.length() == index1){
break;
}

char s1 = s.charAt(index1);
char s2 = t.charAt(index2);

if(s1 == s2){
index2++;
index1++;
}else{
index2++;
}
}

return index1 == s.length();
}
}
``````