func backspaceCompare(_ s: String, _ t: String) -> Bool {
let arrayS = Array(s) , arrayT = Array(t)
var m = arrayS.count - 1 ,n = arrayT.count - 1
var tempM = 0 ,tempN = 0 ,valueM :Character = " " ,valueN :Character = " "
while true {
if m >= 0 {
valueM = arrayS[m]
}else {
valueM = " "
}
if n >= 0 {
valueN = arrayT[n]
}else {
valueN = " "
}
if valueM == " " && valueN == " " {
return true
}
if valueM == "#"{
tempM += 1
m -= 1
}else if valueN == "#"{
tempN += 1
n -= 1
}
else if tempM != 0 {
m -= 1
tempM -= 1
}else if tempN != 0 {
n -= 1
tempN -= 1
}
else if valueM == valueN {
m -= 1
n -= 1
}
else if valueM != valueN {
return false
}
}
}
网友评论