웅재의 코딩세상

[프로그래머스] 접미사인지 확인하기 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 접미사인지 확인하기

웅드 2024. 1. 25. 16:58

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

int solution(string my_string, string is_suffix) {
    int answer = 0;
    int n=0;
    if(is_suffix.size() > my_string.size()) return 0;
    for(int i= is_suffix.size()-1; i >= 0; i--){
        n++;
        if(is_suffix[i] != my_string[my_string.size()-n]) return 0;
    }
    return 1;
}
반응형