1624两个相同字符之间的最长子字符串1876长度为三且各字符不同的子字符串692前K个高频单词1295统计位数为偶数的数字

文章目录

1624

在这里插入图片描述
代码

class Solution {
    public int maxLengthBetweenEqualCharacters(String s) {
        Map<Character,Integer> map=new HashMap<>();
        int max=-1;
        for(int i=0;i<s.length();i++){
            if(map.containsKey(s.charAt(i))){
                max=Math.max(max,i-map.get(s.charAt(i))-1);


            }else{
                map.put(s.charAt(i),i);
            }
        }
        return max;
}
}

1876

1876
一个朴实无华的思路 太朴实了

class Solution {
    public int countGoodSubstrings(String s) {
        int count=0;
        for(int i=0;i<=s.length()-3;i++){
            if(s.charAt(i)!=s.charAt(i+1)&&s.charAt(i)!=s.charAt(i+2)&&s.charAt(i+1)!=s.charAt(i+2)){
                count++;
            }
        }
        return count;
    }
}

692

在这里插入图片描述
代码

class Solution {
    public List<String> topKFrequent(String[] words, int k) {
        Map<String,Integer> map=new HashMap<>();//放入哈希表中
        for(String word:words){
            map.put(word,map.getOrDefault(word,0)+1);
        }
        List<String>res=new ArrayList<>();
        for(Map.Entry<String,Integer> entry:map.entrySet()){
            res.add(entry.getKey());
        }
        Collections.sort(res,new Comparator<String>(){
            public int compare(String word1,String word2){
                return map.get(word1)==map.get(word2)?word1.compareTo(word2):map.get(word2)-map.get(word1);
            }
        });
        return res.subList(0,k);

    }
}

1295

在这里插入图片描述
朴素的暴力求解

class Solution {
    public int findNumbers(int[] nums) {
        int count=0;
        for(int i=0;i<nums.length;i++){
            if((nums[i]>9&&nums[i]<100)||(nums[i]>999&&nums[i]<10000)||(nums[i]>99999)){
                count++;
            }

        }
        return count;

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值