class Solution {
public boolean backspaceCompare(String s, String t) {
int[] s1 = new int[s.length()];
int s1Len = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != '#'){
s1[s1Len++] = s.charAt(i);
}else{
s1Len = Math.max(0,s1Len - 1);
}
}
int[] t1 = new int[t.length()];
int t1Len = 0;
for (int i = 0; i < t.length(); i++) {
if (t.charAt(i) != '#'){
t1[t1Len++] = t.charAt(i);
}else{
t1Len = Math.max(0,t1Len - 1);
}
}
if (t1Len != s1Len) return false;
for (int i = 0; i < t1Len; i++) {
if (t1[i] != s1[i]) return false;
}
return true;
}
}
844. 比较含退格的字符串
最新推荐文章于 2024-08-29 19:36:07 发布