剑指Offer—34—第一个只出现一次的字符位置
来源:互联网 发布:三星手机 数据恢复 编辑:程序博客网 时间:2024/05/29 16:49
第一个只出现一次的字符位置 : 在一个字符串(1 <= 字符串长度 <= 10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置.
package A34第一个只出现一次的字符;public class Solution { public int FirstNotRepeatingChar(String str) { char[] a = str.toCharArray(); int[] count = new int[26]; int[] count2 = new int[26]; for (int i = 0; i < a.length; i++) { if (a[i]-'a' >=0 && a[i]-'a' <= 25 ){ count[a[i]-'a']++; }else if (a[i]-'A' >=0 && a[i]-'A' <= 25){ count2[a[i]-'A']++; } } for (int i = 0; i < a.length; i++) { if (a[i]-'a' >=0 && a[i]-'a' <= 25 && count[a[i]-'a'] == 1 ){ return i; }else if (a[i]-'A' >=0 && a[i]-'A' <= 25 && count2[a[i]-'A'] == 1){ return i; } } return -1; } public static void main(String[] args) { Solution solution = new Solution(); //System.out.println(solution.FirstNotRepeatingChar("kYVmIJVzYWPQLtIdKMmvkVSoKtqJANOfCCOfLVJEjjhbnPrDOwKCDeqhts")); System.out.println('z'-'a'); }}
阅读全文
0 0
- 剑指Offer——(34)第一个只出现一次的字符位置
- 剑指Offer—34—第一个只出现一次的字符位置
- 《剑指offer》第一个只出现一次的字符位置
- 剑指offer:第一个只出现一次的字符位置
- 剑指Offer--第一个只出现一次的字符位置
- 【剑指Offer】第一个只出现一次的字符位置
- 剑指offer:第一个只出现一次的字符位置
- [剑指offer]第一个只出现一次的字符位置
- 《剑指offer》-第一个只出现一次的字符位置
- 剑指offer|第一个只出现一次的字符位置
- 【剑指Offer】第一个只出现一次的字符位置
- 剑指offer:第一个只出现一次的字符位置
- 《剑指offer》——第一个只出现一次的字符位置
- 剑指offer—第一个只出现一次的字符位置
- 剑指offer 34 第一个只出现一次的字符位置
- 第一个 只出现一次的字符 位置(剑指offer)+哈希
- 码农小汪-剑指Offer之32 -第一个只出现一次的字符位置
- 剑指Offer--035-第一个只出现一次的字符位置
- 3223: Tyvj 1729 文艺平衡树
- 找第一个只出现一次的字符
- 【netbeans】Your active platform is: JDK_1.6, but the corresponding property...怎么解决
- Shell简单笔记
- jQuery实现二级联动
- 剑指Offer—34—第一个只出现一次的字符位置
- Unity_简易飞机大战制作(一)
- HTML5多媒体
- 基于MapReduce的二次排序
- windows8.1+VS2013下CUDA7.5配置
- 初阶一层的星号*玩法
- 网页中调用百度地图API
- 剑指Offer—35—数组中的逆序对
- 点击图片弹出文件选择框并覆盖原图功能