contains를 사용해서 ad를 포함하지 않는것만 저장하면 되지 않을까
class Solution {
public String[] solution(String[] strArr) {
ArrayList<String> list = new ArrayList<>();
for(String str : strArr){
if (!str.contains("ad")) {
list.add(str);
}
}
String[] answer =list.toArray(new String[list.size()]);
return answer;
}
}
ArrayList
를 사용한 이유 : 배열의 경우에는 배열크기를 동적으로 변경할수 없다. ArrayList의 경우 동적으로 배열크기를 지정할수 있으므로 바로바로 ad를 포함하지 않는경우를 list에 저장한 후에 array로 변형했다.