当前位置:网站首页>242. Valid Letter ectopic words (hash table)
242. Valid Letter ectopic words (hash table)
2022-04-23 10:15:00 【Popuessing's Jersey】
Given two strings s and t , Write a function to determine t Whether it is s Letter heteronym of .
Example 1: Input : s = "anagram", t = "nagaram" Output : true
Example 2: Input : s = "rat", t = "car" Output : false
Suppose the string contains only lowercase letters .
public boolean isAnagram(String s,String t){
// Create a new array to record the number of occurrences of each character
int [] record = new int [26];
// Traversal string , If the character appears once , Appear value plus one
for (char c:s.toCharArray()) {
record[c-'a']+=1;
}
for (char c:t.toCharArray()) {
record[c-'a']-=1;
}
// If every value in the array is 0, Then the two strings are letter ectopic words
for (int x:record) {
if (x!=0){
return false;
}
}
return true;
}
public static void main(String[] args) {
String s = "faker";
String t = "kafer";
Youxuaidezunyyiweici youxuaidezunyyiweici = new Youxuaidezunyyiweici();
boolean b = youxuaidezunyyiweici.isAnagram(s,t);
System.out.println(b);
}
Output results :
True
版权声明
本文为[Popuessing's Jersey]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231011140858.html
边栏推荐
- 域名和IP地址的联系
- Solve the problem of installing VMware after uninstalling
- Realizing data value through streaming data integration (5) - flow analysis
- Computer network security experiment II DNS protocol vulnerability utilization experiment
- Yarn resource scheduler
- 一文看懂 LSTM(Long Short-Term Memory)
- SQL tuning series - Introduction to SQL tuning
- LeetCode-608. Tree node
- JUC concurrent programming 09 -- source code analysis of condition implementation
- 19、删除链表的倒数第N个节点(链表)
猜你喜欢
MapReduce核心和基础Demo
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
解决VMware卸载后再安装出现的问题
MapReduce计算流程详解
Operation of 2022 tea artist (primary) test question simulation test platform
Configuration of LNMP
Solution architect's small bag - 5 types of architecture diagrams
MapReduce compression
JUC concurrent programming 09 -- source code analysis of condition implementation
《Redis设计与实现》
随机推荐
Art template template engine
杰理之有时候定位到对应地址的函数不准确怎么办?【篇】
59、螺旋矩阵(数组)
Six practices of Windows operating system security attack and defense
Sim Api User Guide(8)
2022年广东省安全员A证第三批(主要负责人)考试试题及答案
Yarn core parameter configuration
LeetCode-608. 树节点
一文看懂 LSTM(Long Short-Term Memory)
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
一文读懂PlatoFarm新经济模型以及生态进展
Sim Api User Guide(6)
Jerry's factors that usually affect CPU performance test results are: [article]
【无标题】
Turn: Maugham: reading is a portable refuge
Sim Api User Guide(4)
Function realization of printing page
DBA common SQL statements (2) - SGA and PGA
Common DBA SQL statements (4) - Top SQL
Sim Api User Guide(8)