当前位置:网站首页>力扣每日一练之字符串Day6
力扣每日一练之字符串Day6
2022-06-23 18:37:00 【InfoQ】
力扣每日一练之字符串Day6
LeetCode 387.字符串中的第一个唯一的字符
示例 1:
输入: s = "leetcode"
输出: 0
示例 2:
输入: s = "loveleetcode"
输出: 2
示例 3:
输入: s = "aabb"
输出: -1
解题思路
源代码
class Solution {
public int firstUniqChar(String s) {
for (int i = 0; i < s.length(); i++) {
if (s.indexOf(s.charAt(i)) == s.lastIndexOf(s.charAt(i))) {
return i;
}
}
return -1;
}
}
🦪LeetCode383.赎金信
示例 1:
输入:ransomNote = "a", magazine = "b"
输出:false
示例 2:
输入:ransomNote = "aa", magazine = "ab"
输出:false
示例 3:
输入:ransomNote = "aa", magazine = "aab"
输出:true
解题思路
源代码
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int [] count=new int[26];
for(char m:magazine.toCharArray()){
count[m-'a']++;
}
for(char r:ransomNote.toCharArray()){
if(count[r-'a']<=0)return false;
count[r-'a']--;
}
return true;
}
}
Leetcode242.有效的字母异位词
示例 1:
输入: s = "anagram", t = "nagaram"
输出: true
示例 2:
输入: s = "rat", t = "car"
输出: false
🥫解题思路
源代码
class Solution {
public boolean isAnagram(String s, String t) {
if(s.length()!=t.length()){
return false;
}
char[] str1=s.toCharArray();
char[] str2=t.toCharArray();
Arrays.sort(str1);
Arrays.sort(str2);
return Arrays.equals(str1,str2);
}
}
总结
觉得文章写的不错的亲亲,点赞评论关注走一波,爱你们哦
边栏推荐
- 【云动向】华为云云商店品牌全新发布 4大亮点都在这儿
- Check four WiFi encryption standards: WEP, WPA, WPA2 and WPA3
- Flagai Feizhi: AI basic model open source project, which supports one click call of OPT and other models
- Approximate fair queuing on programmable switches reading notes
- Online text entity extraction capability helps applications analyze massive text data
- 如何使用物联网低代码平台进行流程管理?
- 从零开发小程序和公众号【第一期】
- Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source! (high performance + high customization)
- 【NOI2014】15.起床困难综合症【二进制】
- sed replace \tPrintf to \t//Printf
猜你喜欢

LeetCode 1079. 活字印刷

IDEA控制台显示中文乱码

Vprom notes

Nanxin semiconductor rushes to the scientific innovation board: its annual revenue is RMB 980 million. Sequoia Xiaomi oppo is the shareholder

Docker builds redis cluster

基于 ShardingSphere 的得物数据库中间件平台“彩虹桥”演进之路
![Jerry's DAC output mode setting [chapter]](/img/b4/64fe92308c16d0cd8c29fee8ad28d8.png)
Jerry's DAC output mode setting [chapter]

直播分享| 腾讯云 MongoDB 智能诊断及性能优化实践

Docker搭建redis集群

IOT platform construction equipment, with source code
随机推荐
Summary of accelerating mobile applications at network edge with software programmable FPGA
19 classic cases of generator functions
Robust extraction of specific signals with time structure (Part 1)
8、AI医生案例
Develop small programs and official account from zero [phase II]
Halcon knowledge: contour operator on region (1)
Uniswap创始人:不会为Genie发行独立代币,Genie产品将集成至Uniswap界面
解读2022年度敏捷教练行业现状报告
在线文本实体抽取能力,助力应用解析海量文本数据
Shengke communication IPO meeting: annual revenue of 460million China Zhenhua and industry fund are shareholders
【One by One系列】IdentityServer4(八)使用EntityFramework Core对数据进行持久化
如何在Microsoft Exchange 2010中安装SSL证书
打新债好不好 打新债安全吗
LeetCode 1079. 活字印刷
考PMP有用吗?
Ready to migrate to the cloud? Please accept this list of migration steps
Function definition and function parameters
活动报名 | MongoDB 5.0 时序存储特性介绍
Ges graph computing engine hyg unveils the secrets of Graph Segmentation
[one by one series] identityserver4 (IV) authorization code process