首页 > 其他分享 >100291. 统计特殊字母的数量 II

100291. 统计特殊字母的数量 II

时间:2024-04-21 12:11:30浏览次数:18  
标签:100291 char 特殊 word 示例 int 字母 II

给你一个字符串 word。如果 word 中同时出现某个字母 c 的小写形式和大写形式,并且 每个 小写形式的 c 都出现在第一个大写形式的 c 之前,则称字母 c 是一个 特殊字母 。

返回 word 中 特殊字母 的数量。

 

示例 1:

输入:word = "aaAbcBC"

输出:3

解释:

特殊字母是 'a''b' 和 'c'

示例 2:

输入:word = "abc"

输出:0

解释:

word 中不存在特殊字母。

示例 3:

输入:word = "AbBCab"

输出:0

解释:

word 中不存在特殊字母。

 

提示:

  • 1 <= word.length <= 2 * 105
  • word 仅由小写和大写英文字母组成。
class Solution {
    public int numberOfSpecialChars(String word) {
        int res = 0;
        Map<Character, Integer> lowerMap = new HashMap<>();
        Map<Character, Integer> upperMap = new HashMap<>();
        for(int i =0;i<word.length();i++){
            char c = word.charAt(i);
            if(c>='a' && c <='z') {
                lowerMap.put(c,i);
            }
            else if (c>='A' && c<='Z'  && !upperMap.containsKey(c)){
                upperMap.put(c, i);
            }
        }
        for(Map.Entry<Character,Integer> entry : lowerMap.entrySet()){
            char lower = entry.getKey();
            int position = entry.getValue();
            char upper = (char) (lower-32);
            if(upperMap.containsKey(upper)){
                if(position < upperMap.get(upper)){
                    res += 1;
                }

            }
        }
        return res;
    }
}

 

标签:100291,char,特殊,word,示例,int,字母,II
From: https://www.cnblogs.com/ak918xp/p/18148768

相关文章

  • LeetCode 1424. Diagonal Traverse II
    原题链接在这里:https://leetcode.com/problems/diagonal-traverse-ii/description/题目:Givena2Dintegerarray nums,return allelementsof nums indiagonalorderasshowninthebelowimages.Example1:Input:nums=[[1,2,3],[4,5,6],[7,8,9]]Output:[1,4,......
  • 32天【代码随想录算法训练营34期】第八章 贪心算法 part02 (● 122.买卖股票的最佳时
    122.买卖股票的最佳时机IIclassSolution:defmaxProfit(self,prices:List[int])->int:result=0foriinrange(len(prices)-1):ifprices[i+1]-prices[i]>0:result+=prices[i+1]-prices[i]return......
  • Reflective Journal II
    (1)Becausethecharacterisspecial,firstIneedtogetfamiliarwiththecharacter,learnfromhimtogetabetterandthoroughperspective.NextIhavetodosomeresearchfromtheinternetandgetsomeinformationandsomephotostomakethepptbetter.......
  • Reflective Journal II
    ItwasmyfirsttimetomakeaDMCproject-videopresentation.whenIsawtherequest,Iimmediatelyrememberedmyphysicsteacherinmyhighschool.Heaffectedmealot.HisPPTwaseasytomake.Ifrequentlyusephotographandsentencetodescriblehisappr......
  • Reflective journal II
    (1)Firstofall,Ineedtochooseapeopletopresentate.Then,Ichosesomeaspectsofherandwrotedowndetaileddiscriptionofthese.Atthesametime,Iaskedherwhetherhermindbeingpresentated.Iflippedthroughmyalbumbutcouldnotfindanyphotos......
  • Reflective Journal II
    AfterIwasaskedtodoavideopresentation,IdecidedwhoIwasgoingtointroduceandwhattocoverinmypresentationatfirst.ThenIbegantowritethetextinthePPT.Duringtheprocess,ImadeafewadjustmentstomakemyPPTmoreaesthetic.Fina......
  • IIS 执行此操作时出错。 详细信息:web.config 错误,.net core项目
    一、IIS执行此操作时出错。详细信息:web.config错误,.netcore项目   运行报错错误信息提示的很明确:IISWebCore模块问题二、解析:IIS下报错,但是直接启动exe文件可以正常运行。 三、解决方案先安装IIS,然后安装Asp.netCore运行时。 更多:IIS10隐藏https......
  • 十六进制字符串每隔32个字母换行显示
     //每32个字节换行打印publicstaticvoidformatPrint(StringhexStr){intno=0;intlength=hexStr.length();for(inti=0;i<length;i++){if((i+1)%32==0){Strings=twoSpaceTwo(hexStr.substring(i-31,i+1));System.out.println(......
  • IIS 部署WEBAPI
    ASP.NETCore不再是由IIS工作进程(w3wp.exe)托管,而是使用自托管Web服务器(Kestrel)运行,IIS则是作为反向代理的角色转发请求到Kestrel不同端口的ASP.NETCore程序中,随后就将接收到的请求推送至中间件管道中去,处理完你的请求和相关业务逻辑之后再将HTTP响应数据重新回写到IIS中,最终转达......
  • Quartus 配置 Nios® II EDS 开发
    安装Quartus按照我之前写的文章安装即可——Quartus入门安装Ubuntu18.04(Linux桌面用户直接跳过该步骤)在官方下载页面可以看到,我们需要安装Ubuntu18.04LTS并启用WSLWSL这里介绍WSL的安装方法,打算使用WSL2的读者请根据需要阅读本文中的参考链接使用管理......