코테준비 - Wildcard Matching

정상화·2023년 2월 26일

LeetCode

목록 보기
42/222

Wildcard Matching

class Solution {
public:
    bool isMatch(string s, string p) {
        unsigned i,j;
        int ss,star;
        i = j = 0;
        ss = star = -1;
        while (i < s.length()) {
            if (j >= p.length() ||
                    !((s.at(i) == p.at(j) || p.at(j) == '?') || p.at(j) == '*')) {
                if(star == -1) return false;
                i = ++ss;
                j = star + 1;
            }
            else if (s.at(i) == p.at(j) || p.at(j) == '?') {
                i++;
                j++;
            } else if(p.at(j) == '*'){
                ss = i;
                star = j++;
            }
        }

        if (i == s.length() && j < p.length()) {
            for (; j < p.length(); j++) {
                if (p.at(j) != '*') {
                    return false;
                }
            }
            return true;
        }
        return true;
    }
};
profile
백엔드 희망

0개의 댓글