Algorithm/프로그래머스

[알고리즘] 접미사인지 확인하기 Java

rw- 2023. 6. 27. 22:00
728x90

 

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

class Solution {
    public int solution(String my_string, String is_suffix) {
        List<String> collect = IntStream.range(0, my_string.length())
            .mapToObj(my_string::substring)
            .collect(Collectors.toList());
  
        return collect.stream().anyMatch(Predicate.isEqual(is_suffix)) ? 1 : 0;
    }
}

 

다른 사람의 풀이

class Solution {
    public int solution(String myString, String isSuffix) {
        return myString.endsWith(isSuffix) ? 1 : 0;
    }
}

 

728x90
반응형