• 371. Find the Longest Substring Containing Vowels in Even Counts


    Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.

    Example 1:

    Input: s = "eleetminicoworoep"
    Output: 13
    Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.
    

    Example 2:

    Input: s = "leetcodeisgreat"
    Output: 5
    Explanation: The longest substring is "leetc" which contains two e's.
    

    Example 3:

    Input: s = "bcbcbc"
    Output: 6
    Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.
    

    Constraints:

    • 1 <= s.length <= 5 x 10^5
    • s contains only lowercase English letters.
    class Solution {
        public int findTheLongestSubstring(String s) {
            int le = s.length();
            int ans = 0;
            for(int i = 0; i < le; i++){
                for(int j = i + 1; j <= le; j++){
                    if(helper(s.substring(i, j))){
                        ans = Math.max(ans, j - i);
                    }
                }
            }
            return ans;
        }
        public boolean helper(String s){
            boolean res = false;
            int aa = 0, ee = 0, ii = 0, oo = 0, uu = 0;
            for(char c: s.toCharArray()){
                if(c == 'a') aa++;
                else if(c == 'e') ee++;
                else if(c == 'i') ii++;
                else if(c == 'o') oo++;
                else if(c == 'u') uu++;
            }
            return (aa % 2 == 0 &&  ee % 2 == 0 && ii % 2 == 0 && oo % 2 == 0 && uu % 2 == 0 );
        }
    }

    brute force, 果然TLE了。。

  • 相关阅读:
    Prestashop-1.6.1.6-zh_CN (Openlogic CentOS 7.2)
    青石B2C商城
    装ubuntu的坑
    欧式空间和欧式距离、曼哈顿距离
    卷积神经网络入门
    pointnet++论文的翻译
    度量空间
    ppt演讲者视图不可用的解决办法
    pointnet
    Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
  • 原文地址:https://www.cnblogs.com/wentiliangkaihua/p/12460245.html
Copyright © 2020-2023  润新知