当前位置:网站首页>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
边栏推荐
- 解决VMware卸载后再安装出现的问题
- MapReduce核心和基础Demo
- 通过流式数据集成实现数据价值(2)
- Sim Api User Guide(5)
- JUC concurrent programming 07 -- is fair lock really fair (source code analysis)
- SQL tuning series - Introduction to SQL tuning
- ARM调试(1):两种在keil中实现printf重定向到串口的方法
- Yarn core parameter configuration
- Zhengda international explains what the Dow Jones industrial index is?
- 杰理之通常影响CPU性能测试结果的因素有:【篇】
猜你喜欢
随机推荐
Yarn resource scheduler
LeetCode-608. 树节点
Understand the new economic model of platofarm and its ecological progress
Failureforwardurl and failureurl
DBA common SQL statements (5) - latch related
art-template 模板引擎
杰理之系统事件有哪些【篇】
JUC concurrent programming 09 -- source code analysis of condition implementation
Jerry's factors that usually affect CPU performance test results are: [article]
Six practices of Windows operating system security attack and defense
2022 mobile crane driver test question bank simulation test platform operation
Computer network security experiment II DNS protocol vulnerability utilization experiment
定义链表(链表)
DBA common SQL statements (2) - SGA and PGA
Sim Api User Guide(8)
Longest common front string
LeetCode-608. Tree node
第二章 In-Memory 体系结构 (IM-2.2)
209. Subarray with the smallest length (array)
Sim Api User Guide(7)