seunghyun Note

[프로그래머스] - 부분 문자열인지 확인하기 with JAVA 본문

코딩테스트/백준

[프로그래머스] - 부분 문자열인지 확인하기 with JAVA

승숭슝현 2024. 1. 6. 22:28

링크 : https://school.programmers.co.kr/learn/courses/30/lessons/181843

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제 풀이

 

문제를 푸는게 중요하다. 간단하게 못해도 해결할 수 있다는 것이 코테의 매력이고 실력 향상에 좋은거 같다. (라고 합리화 시작)

contains(CharSequence s)
Returns true if and only if this string contains the specified sequence of char values.

Contains를 사용하는 법부터 보자!

public class ContainsTest{
    public static void main(String[] args){

        String str = "my java test";

        System.out.println( str.contains("java") );  // true
        System.out.println( str.contains(" my") );  // false
        System.out.println( str.contains("JAVA") );  // false
        System.out.println( str.contains("java test") );  // true

    }

}

해결.!

class Solution {
    public int solution(String my_string, String target) {
        
        return my_string.contains(target)? 1: 0;
    }
}

 

728x90