zoukankan      html  css  js  c++  java
  • 809. Expressive Words

    https://leetcode.com/problems/expressive-words/description/

    class Solution {
    public:
        int expressiveWords(string S, vector<string>& words) {
            int res = 0; 
            for (const auto& w : words) {
                if (check(S, w))
                    res++;
            }
            return res;
        }
        bool check(const string& s, const string& w) {
            int i = 0, j = 0, m = s.length(), n = w.length();
            while (i < m && j < n) {
                if (s[i] != w[j])   return false;
                int ii = 1, jj = 1;
                while (++i < m && s[i] == s[i-1]) ii++;
                while (++j < n && w[j] == w[j-1]) jj++;
                if (ii < jj || ii < 3 && ii != jj)    return false;
            }
            return i == m && j == n;
        }
    };
  • 相关阅读:
    poj 2104 C
    2015 百度之星初赛 1 2 2015ACM/ICPC亚洲区上海站 codeforces 851
    3.10补
    3.9补
    3.8补
    3.6补
    3.5补
    3.4补
    3.3补
    2.35补
  • 原文地址:https://www.cnblogs.com/JTechRoad/p/8984799.html
Copyright © 2011-2022 走看看