如何消除两个字符串之间具有相同索引的相同字符?

问题描述 投票:-3回答:1

例如,两个字符串分别为"hello""sello"(或者也可以是["h","e","l","l","o"]["s","e","l","l","o"]它删除两个字符串之间具有相同索引的相同字符。

消除循环之后,它应该分别返回"h""s"

例如,两个字符串分别为"sony""nani"那么它应该返回"soy""nai"

python character word
1个回答
0
投票
String a = "hello";
String b = "hallo world";
int strLen = b.length();
for(int i=0;i<length;i++){
if(a.charAt(i)==b.charAt(i))
  {
     charRemoveAt(a,i);
     charRemoveAt(b,i);
     i--;
     length--;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.