当前位置:网站首页>String Day6 of Li Kou daily practice
String Day6 of Li Kou daily practice
2022-06-23 19:37:00 【InfoQ】
Force buckle the string of one practice per day Day6
LeetCode 387. The first unique character in the string
Example 1:
Input : s = "leetcode"
Output : 0
Example 2:
Input : s = "loveleetcode"
Output : 2
Example 3:
Input : s = "aabb"
Output : -1
Their thinking
Source code
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. Ransom letter
Example 1:
Input :ransomNote = "a", magazine = "b"
Output :false
Example 2:
Input :ransomNote = "aa", magazine = "ab"
Output :false
Example 3:
Input :ransomNote = "aa", magazine = "aab"
Output :true
Their thinking
Source code
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. Effective alphabetic words
Example 1:
Input : s = "anagram", t = "nagaram"
Output : true
Example 2:
Input : s = "rat", t = "car"
Output : false
🥫 Their thinking
Source code
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);
}
}
summary
I think the article is well written , Like comments, pay attention to a wave , Love you
边栏推荐
- 如何使用物联网低代码平台进行流程管理?
- Matrix analysis notes (I)
- 游戏资产复用:更快找到所需游戏资产的新方法
- How to use the low code platform of the Internet of things for process management?
- A review of comparative learning
- How to avoid the "black swan" incident in the gene field: a security war behind a preventive "recall"
- #20Set介绍与API
- Develop small programs and official account from zero [phase II]
- Docker builds redis cluster
- Develop small programs and official account from zero [phase I]
猜你喜欢

金九银十,靠这个细节,offer拿到手软!

#20Set介绍与API

技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放

FlagAI飞智:AI基础模型开源项目,支持一键调用OPT等模型

Kotlin jetpack compose Tab的渲染 AnimatedVisibility的使用

区块哈希竞猜游戏系统开发(dapp)

JDBC 在性能測試中的應用

硬件开发笔记(六): 硬件开发基本流程,制作一个USB转RS232的模块(五):创建USB封装库并关联原理图元器件

How to write a great online user manual in 7 steps

The golden nine silver ten, depends on this detail, the offer obtains the soft hand!
随机推荐
The yuan universe killer is coming! Xiao Zha offered 4 VR head displays to challenge the visual Turing test
Requirements and precautions for applying for multi domain SSL certificate
Advanced network accounting notes (IV)
How to avoid the "black swan" incident in the gene field: a security war behind a preventive "recall"
八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?
基于微信小程序的婚纱影楼小程序开发笔记
Idea console displays Chinese garbled code
【One by One系列】IdentityServer4(六)授权码流程原理之SPA
Principles of microcomputer Chapter 5 notes arrangement
LeetCode 1079. movable-type printing
解读2022年度敏捷教练行业现状报告
What are the useful personnel management software? Personnel management system software ranking!
Netcf summary
The golden nine silver ten, depends on this detail, the offer obtains the soft hand!
Matrix analysis notes (III-1)
LeetCode 473. 火柴拼正方形
8. AI doctor case
Check four WiFi encryption standards: WEP, WPA, WPA2 and WPA3
Advanced network accounting notes (V)
函数的定义和函数的参数