[力扣]——387.字符串中的第一个唯一字符

. - 力扣(LeetCode)

java 复制代码
class Solution {
    public int firstUniqChar(String s) {
        int[] count = new int[256];
        // 统计每个字符出现的次数
        for(int i = 0; i < s.length(); ++i){
            count[s.charAt(i)]++;
       }
 
        // 找第一个只出现一次的字符
        for(int i = 0; i < s.length(); ++i){
            if(1 == count[s.charAt(i)]){
                return i;
           }
       }
 
        return -1;
   }
}
相关推荐
Lsk_Smion21 小时前
Hot100(开刷) 之 LRU(最近最少使用)缓存
力扣
玛卡巴卡ldf2 天前
【LeetCode 手撕算法】(多维动态规划)不同路径、最小路径和、最长回文子串、最长公共子序列、编辑距离
java·数据结构·算法·leetcode·动态规划·力扣
旖-旎4 天前
深搜练习(单词搜索)(12)
c++·算法·深度优先·力扣
玛卡巴卡ldf5 天前
【LeetCode 手撕算法】(动态规划)爬楼梯、杨辉三角、打家劫舍、完全平方数、零钱兑换、单词拆分、最长递增子序列、乘积最大子数组、分割等和子集
java·数据结构·算法·leetcode·动态规划·力扣
玛卡巴卡ldf8 天前
【LeetCode 手撕算法】(栈)有效括号、最小栈、字符串解码、每日温度、柱状图最大矩形
java·数据结构·算法·leetcode·力扣
小辉同志11 天前
62. 不同路径
c++·力扣·多维动态规划
玛卡巴卡ldf11 天前
【LeetCode 手撕算法】(回溯)全排列DFS、子集、电话号码字母组合 九键、组合总和、括号生成、单词搜索、分割回文数
java·算法·leetcode·力扣
mask哥12 天前
15种算法模式java实现详解
java·算法·力扣
旖-旎16 天前
深搜练习(N皇后)(10)
c++·算法·深度优先·力扣
加农炮手Jinx17 天前
LeetCode 26. Remove Duplicates from Sorted Array 题解
算法·leetcode·力扣