포스트

꼬리 문자열

https://school.programmers.co.kr/learn/courses/30/lessons/181841

문제

  • 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.ArrayList;
import java.util.List;

public class Solution {
    public static String solution(String[] str_list, String ex) {
        StringBuilder result = new StringBuilder();
        for (String str : str_list) {
            if (!str.contains(ex)) {
                result.append(str);
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        String[] str_list1 = {"abc", "def", "ghi"};
        String[] str_list2 = {"abc", "bbc", "cbc"};
        System.out.println(solution(str_list1, "ef")); // 출력: "abcghi"
        System.out.println(solution(str_list2, "c"));  // 출력: ""
    }
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.