Make The String Great
给一个字符串, 定义一个字符串是good: 相邻的两个字符不是同样的一个字符的大小写. 问当删去所有的good后的字符串.
class Solution {
public String makeGood(String s) {
if(s == null || s.length() == 1 || s.length() == 0)
return s;
boolean found = false;
while(true) {
found = false;
for(int i = 0; i < s.length() - 1; i++) {
if(s.charAt(i) != s.charAt(i+1) &&(Character.toUpperCase(s.charAt(i)) == s.charAt(i+1) || Character.toUpperCase(s.charAt(i+1)) == s.charAt(i))) {
s = s.substring(0, i) + s.substring(i + 2, s.length());
found = true;
}
}
if(!found)
return s;
}
}
}