当前位置:网站首页>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
边栏推荐
- 【无标题】
- 206、反转链表(链表)
- Zhengda international explains what the Dow Jones industrial index is?
- DBA common SQL statements (5) - latch related
- 转:毛姆:阅读是一座随身携带的避难所
- Realize data value through streaming data integration (1)
- 2022 mobile crane driver test question bank simulation test platform operation
- Chapter 1 Oracle database in memory related concepts (im-1.1)
- DBA常用SQL语句 (5) - Latch 相关
- Sim Api User Guide(6)
猜你喜欢

IDEA——》每次启动都会Indexing或 scanning files to index

2022年流动式起重机司机考试题库模拟考试平台操作

2022年上海市安全员C证考试题库及答案
MapReduce核心和基础Demo

Sim Api User Guide(5)

Sim Api User Guide(4)

JVM——》常用命令

Solve the problem of installing VMware after uninstalling

Reading integrity monitoring techniques for vision navigation systems - 3 background

2022 mobile crane driver test question bank simulation test platform operation
随机推荐
Chapter I Oracle database in memory related concepts (Continued) (im-1.2)
Redis design and Implementation
Question bank and answers of Shanghai safety officer C certificate examination in 2022
Rain produces hundreds of valleys, and all things grow
SQL调优系列文章之—SQL性能方法论
解决方案架构师的小锦囊 - 架构图的 5 种类型
Juc并发编程07——公平锁真的公平吗(源码剖析)
正大国际讲解道琼斯工业指数到底是什么?
Examination questions and answers of the third batch (main person in charge) of Guangdong safety officer a certificate in 2022
Reading integrity monitoring techniques for vision navigation systems - 3 background
Jerry's factors that usually affect CPU performance test results are: [article]
Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]
通过流式数据集成实现数据价值(2)
142、环形链表||
Juc并发编程06——深入剖析队列同步器AQS源码
一文看懂 LSTM(Long Short-Term Memory)
杰理之栈溢出 stackoverflow 怎么办?【篇】
[untitled]
第一章 Oracle Database In-Memory 相关概念(续)(IM-1.2)
349、两个数组的交集