방명록
- [프로그래머스 / 자바] 접미사인지 확인하기2023년 11월 09일 16시 39분 26초에 업로드 된 글입니다.작성자: 민발자728x90
문제
어떤 문자열에 대해서 접미사는 특정 인덱스부터 시작하는 문자열을 의미합니다. 예를 들어, "banana"의 모든 접미사는 "banana", "anana", "nana", "ana", "na", "a"입니다.
문자열 my_string과 is_suffix가 주어질 때, is_suffix가 my_string의 접미사라면 1을, 아니면 0을 return 하는 solution 함수를 작성해 주세요.풀이
class Solution { public int solution(String my_string, String is_suffix) { int answer = 0; for(int i = 0; i < my_string.length(); i++){ if(my_string.substring(i).equals(is_suffix)) answer = 1; } return answer; } }
참고할만한 다른 사람 풀이
class Solution { public int solution(String myString, String isSuffix) { return myString.endsWith(isSuffix) ? 1 : 0; } }
endsWith() 메서드가 있었다🥺
728x90'기록 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 코딩테스트 입문 문제 완료 (0) 2023.11.13 [프로그래머스 / 자바] 이진수 더하기 (0) 2023.11.13 [프로그래머스 / 자바] 숫자 찾기 (0) 2023.10.28 [프로그래머스 / 자바] 약수구하기 (0) 2023.10.27 [프로그래머스 / 자바] 세균 증식 (0) 2023.10.25 다음글이 없습니다.이전글이 없습니다.댓글