leetcode:387. First Unique Character in a String

AI应用质量工程实践:从评估到监控的完整体系构建 在软件工程领域,质量保障体系是确保产品稳定可靠的核心机制,涉及度量指标、保障流程和工具链的完整闭环。随着生成式AI应用的快速发展,如何将传统软件工程中的质量门禁思想引入AI领域,成为工程实践的关键挑战。其核心原理在于构建可量化、可监控、可改进的质量评估框架,通过自动化测试、持续监控和反馈优化来管理AI输出的不确定性。这一技术价值在于将AI应用从原型阶段推向产品化,确保输出的一致性、安全性和可靠性。在实际应用场景中,开发者需要从功能性、非功能性、一致性和合规性四个维度构建评估体系,并借助LLM-as-a-Ju 阅读详情

不要慌,搞懂题目先,

思路:

unordered_map 映射好,然后判断:

 

不过好像比大家的慢了好多,为什么呢?有什么更快的呢

class Solution {
public:
    int firstUniqChar(string s) {
        int len=s.length();
        unordered_map<int,int> mp;
        
        for(int i=0;i<len;i++)
        {
            auto idx=s[i]-'a';
            if(mp.count(idx)){//exist, ++the value
                mp.insert(pair<int,int>(idx,(mp[idx])++));
            }
            mp.insert(pair<int,int>(idx,1));//not exist,insert new
        }
        for(int i=0;i<len;i++){//find first non-repeating
            auto idx=s[i]-'a';
            if(mp[idx] <=1 ){
                return i;
            }
        }
        return -1;//none repeat
    }
};

没什么影响,几乎。

class Solution {
public:
    int firstUniqChar(string s) {
        int len=s.length();
        unordered_map<char,int> mp;
        
        for(int i=0;i<len;i++)
        {
            // auto idx=s[i]-'a';
            if(mp.count(s[i])){//exist, ++the value
                mp.insert(pair<char,int>(s[i],(mp[s[i]])++));
            }
            mp.insert(pair<char,int>(s[i],1));//not exist,insert new
        }
        for(int i=0;i<len;i++){//find first non-repeating
            // auto idx=s[i]-'a';
            if(mp[s[i]] <=1 ){
                return i;
            }
        }
        return -1;//none repeat
    }
};

看大佬们怎么写的:

 

缩小循环次数,一次循环记录多个有用数据,尝试一次判断出来。

class Solution {
public:
    int firstUniqChar(string s) {
        unordered_map<char, pair<int, int>> m;
        int idx = s.size();
        for (int i = 0; i < s.size(); i++) {
            m[s[i]].first++;
            m[s[i]].second = i;
        }
        for (auto &p : m) {
            if (p.second.first == 1) idx = min(idx, p.second.second);
        }
        return idx == s.size() ? -1 : idx;
    }
};

 

 

基于YOLOv11的手术器械计数系统:从数据集构建到Web应用部署 m2cai16-tool数据集:包含15种腹腔镜手术器械的标注图像Cholec80数据集:包含80个胆囊切除手术视频,标注了7种器械SurgicalTools数据集:包含超过10,000张手术器械图像,涵盖21类常见器械手术剪(Scissors)止血钳(Hemostat)持针器(Needle Holder)手术刀(Scalpel)镊子(Forceps)拉钩(Retractor)吸引器(Suction) 阅读详情

相关推荐

树莓派CM4 PCIe扩展方案与ASM1184e芯片应用

PCIe(Peripheral Component Interconnect Express)是计算机硬件中重要的高速串行总线标准,广泛应用于存储、网络等设备连接。其核心原理是通过差分信号实现高带宽传输,PCIe Gen2 x1的理论带宽可达5Gbps。在嵌入式开发中,PCIe扩展技术能有效解决单板计算机接口不足的问题,特别适合树莓派等微型平台。ASMedia ASM1184e作为PCIe交换芯片,可将单个接口扩展为多个,支持热插拔且免驱动,极大提升了工程灵活性。通过PCIe交换机方案,开发者能在树莓派CM

weixin_42602368的博客 439

LeetCode: 387. First Unique Character in a String

051105 题目 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: Y...

liveway6的博客 203

PyCharm中安装OpenCV全指南:从环境配置到报错解决

Python开发中,环境配置往往是新手入门的第一道坎。理解解释器、虚拟环境与包管理工具pip之间的关系,是解决ModuleNotFoundError等问题的关键。PyCharm作为常用IDE,其项目默认创建独立虚拟环境,若在系统终端安装的OpenCV与该环境不一致,便会导致import cv2失败。OpenCV作为计算机视觉领域的基础库,广泛应用于图像处理、摄像头调用及深度学习预处理等场景。掌握基于虚拟环境的安装与验证方法,不仅能一次性解决cv2导入错误,还能为后续项目隔离依赖、避免版本冲突打下基础。本文从

weixin_31742871的博客 301

LeetCode之路:387. First Unique Character in a String

LeetCode之路:387. First Unique Character in a String 一、引言这道题题意非常简单,却让我思考了很久,或许难的并不是这道题,是纠结于解题思路的那种困扰吧。这里是这道题: Given a string, find the first non-repeating character in it and return it’s index. If it

(ÒωÓױ) 2241

Python 爬取新浪财经 7x24(1): 下载数据

前言 最近在做一个需要很多财经数据的项目。于是想到可不可以通过爬虫来解决(尝试白嫖)。 提供财经数据的网站有很多个,其中比较靠谱和更新比较及时的应该是新浪7x24 live数据。 http://finance.sina.com.cn/7x24/?tag=0 这个问题有一定的难度,因为这个网页是动态加载的。每一次只会加载部分数据,而只有拉到底部才可以加载新的数据。 于是乎,我们要做的事情是: 下载数据 保存到数据库 本篇介绍如何下载数据。 代码 闲言少叙书归正文,代码的实现如下: import reque

ZJ_11701的博客 2918

Kali实战:构建安卓远程监控工具,实现拍照、定位与信息获取

本文详细介绍了如何使用Kali Linux构建安卓远程监控工具,实现拍照、定位与信息获取功能。通过Metasploit框架生成安卓载荷,部署到目标设备并建立连接,执行远程监控操作如获取位置信息、拍照和读取通讯录。文章还提供了进阶技巧与问题排查方法,强调法律与道德考量。

weixin_28716443的博客 248

LeetCode笔记:387. First Unique Character in a String

找到一个字符串中第一个只出现一次的字母

Minecraft 2363

描边盛开火玫瑰

python描边盛开火玫瑰 代码如下 import turtle as t t.setup(800,800) t.hideturtle() t.speed(11) t.penup() t.goto(50,-450) t.pensize(5) t.pencolor("black") t.seth(140) t.pendown() t.speed(10) t.circle(-300,60) t.fd(100) #jiaodu80 #1ye t.seth(10) t.fd(50) t.fillcolor("gr

weixin_50973371的博客 2075

LeetCode 387:First Unique Character in a String

Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: 

judadeshu的博客 274

告别反复刷写:用英飞凌XCP Overlay功能实现ECU标定与诊断的‘热更新’

本文详细介绍了英飞凌XCP Overlay功能在ECU标定与诊断中的应用,实现参数的'热更新',避免反复刷写Flash。通过地址重映射技术,将标定变量从Flash重定向到RAM,显著提升工作效率并保护Flash寿命。文章涵盖技术原理、工程实践、功能安全考量及高级应用场景,为汽车电子工程师提供完整解决方案。

weixin_30689307的博客 549

【51单片机实物】基于51单片机设计的简易直流电机调测速系统(可用在普中开发板)

功能任务描述:将设置的转速与当前测量的转速比较,得出差值用于控制DAC0832的输出电压,从而控制直流电机的转速,使转速逐渐达到设置转速。在LED上显示设置转速(左2位LED)和当前转速(右2位LED),转速显示采用十进制。控制过程中,当前转速显示不断变化。*直流电机转速范围0-96r/s,误差±1r/s

嵌入式阿齐Archie 1万+

Leetcode 387: First Unique Character in a String

问题描述: Given a string s, return the first non-repeating character in it and return its index. If it does not exist, return -1. 寻找一个字符串里面最早出现的非重复字符,若都有重复则返回-1. 限定条件: 1 <= s.length <= 100000 s consists of only lowercase English letters. 思路: 用哈希表记录字符及其对应

weixin_51401145的博客 139

14、网络切片技术:原理、应用与挑战

本文详细探讨了网络切片技术的原理、应用场景及其在5G网络中的重要性。网络切片作为一种关键的网络架构技术,能够在同一物理网络上创建多个独立的逻辑网络,以满足不同应用对安全性、可靠性和性能的多样化需求。文章深入分析了网络切片在5G、SDN/NFV等技术背景下的发展与挑战,并探讨了其在制造业、交通运输、零售等多个行业的实际应用。此外,还介绍了网络切片的部署流程、未来发展趋势以及相关技术难点,为读者全面了解网络切片技术提供了有价值的参考。

palm99的专栏 263

leetcode387:First Unique Character in a String

要求:找出第一个在字符串中没有重复的字符,返回它在字符串中的位置。 例如:“leetcode'”  返回0     “loveleetcode”返回2 注意:一开始直接暴力破解,遍历数组,将除了当前元素a[i]以外的所有元素放入set集合中,如果这个set也包含一个与a[i]相同的元素,那么继续下一次循环。如果set中没有一个元素与a[i]相同,那么立马返回i。 这种方法可以达到目的,但是字

sinat_35425429的博客 228

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

[leetcode]: 387. First Unique Character in a String

1.题目描述Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. 求一个字符串中第一个只出现一次的字符。 Examples:s = “leetcode” return 0. s = “loveleetcode”,

沐沐余风的专栏 387

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

[leetcode: Python]387.First Unique Character in a String

题目: Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Examples:s = “leetcode” return 0.s = “loveleetcode”, return 2. Note: You may a

cyy2learn的博客 990

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

leetcode OJ:387. First Unique Character in a String

Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. 以下是程序: c

jxfang的专栏 449

【LeetCode & 剑指offer刷题】字符串题1:50 第一个只出现一次的字符(387. First Unique Character in a String)...

【LeetCode &amp; 剑指offer刷题】字符串题1:50 第一个只出现一次的字符(387. First Unique Character in a String) 【LeetCode &amp; 剑指offer 刷题笔记】目录(持续更新中...) 387. First Unique Character in a String G...

技术改变世界 1183

LeetCode 387:first-unique-character-in-a-string

题目:https://leetcode.com/problems/first-unique-character-in-a-string/ 难度:Easy int firstUniqChar(char* s) { int a[26][2]={0}; for(int i=0;i<strlen(s);i++){ a[s[i]-'a'][0]++; ...

weixin_33697898的博客 103

java字符串hash唯一_LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String...

LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String题目:给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。Given a string, find the first non-repeating character in it and return it's index. If it...

weixin_42165490的博客 258

LeetCode:387. First Unique Character in a String字符串中的第一个唯一字符(C语言)

题目描述: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 示例: s = “leetcode” 返回 0 s = “loveleetcode” 返回 2 提示:你可以假定该字符串只包含小写字母。 解答: int firstUniqChar(char * s){ if(NULL == s){ return -1; } int len = 0; int i = 0; int res[26] = {0};

C/C++攻城狮 212

LeetCode //C - 387. First Unique Character in a String

【代码】LeetCode //C - 387. First Unique Character in a String。

Made in Code 976

LeetCode 387. First Unique Character in a String 题解

本题是字符串处理的基础问题。字符计数遍历顺序边界条件处理通过本题可以深入理解哈希表和数组在字符处理中的应用。

cannonjinx的博客 1196

LeetCode387—First Unique Character in a String

LeetCode387 First Unique Character in A String

上善若水 1865

leetcode 387. First Unique Character in a String

目录 一、问题描述 二、代码实现 1、两遍遍历 2、一遍遍历 https://leetcode.com/problems/first-unique-character-in-a-string/ 返回给定字符串第一个只出现一次的字符的下标,不存在则返回-1 一、问题描述 测试用例: s = "leetcode" return 0. s = "loveleetcode...

小景的博客 217

Leetcode PHP题解--D100 387. First Unique Character in a String

D100 387. First Unique Character in a String 题目链接 387. First Unique Character in a String 题目分析 返回给定字符串中第一个只出现了一次的单词下标。 若没有,则返回-1。 思路 把遇到的单词存进两个数组。 ...

247
上一篇: 搬:C++ BOOST库 条件变量[多线程通信]机制 笔记
下一篇: leetcode:268. Missing Number
nedwons
博客等级 码龄9年 311粉丝 572原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值