当前位置:网站首页>Sword finger offer II 032 Effective anagrams
Sword finger offer II 032 Effective anagrams
2022-06-25 12:59:00 【Small white yards fly up】
Summary
The number of characters saved in the hash table , Then compare .
subject
Given two strings s and t , Write a function to determine whether they are a group of modifiers ( Letter heterotopic word ).
Be careful : if s and t The number of occurrences of each character is the same and the character order is not exactly the same , said s and t Each other is a modifier ( Letter heterotopic word ).

link :https://leetcode.cn/problems/dKk3P7
Ideas
Determine whether two strings are equal , Equal return false.
Traverse two strings , Count the number of occurrences of each character , Then compare whether they are equal .
solution : Use the length of 26 The array of is used as a hash table to save the number of characters
Code
public boolean isAnagram(String s, String t) {
if (s.equals(t)) {
return false;
}
int[] sArray = new int[26];
int[] tArray = new int[26];
for (char c : s.toCharArray()) {
sArray[c - 'a']++;
}
for (char c : t.toCharArray()) {
tArray[c - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (sArray[i] != tArray[i]) {
return false;
}
}
return true;
}
边栏推荐
- Geospatial search: implementation principle of KD tree
- 2021-10-21
- Oracle trigger error report table or view does not exist
- Differences between JS and JQ operation objects
- ByteDance dev better technology salon is coming! Participate in the activity to win a good gift, and sign up for free within a limited time!
- Native JS --- infinite scrolling
- Lexical trap
- Negative sample image used in yolov5 training
- 提高排名的 15 个基本 SEO 技巧
- [visio] solving the fuzzy problem of parallelogram in word
猜你喜欢
随机推荐
LeetCode链表题解技巧归纳总结
You can't specify target table 'xxx' for update in from clause
Talk about 11 key techniques of high availability
Elemtnui select control combined with tree control to realize user-defined search method
剑指 Offer II 025. 链表中的两数相加
Serevlt初识
5 kinds of viewer for browser
torch. Tensor splicing and list (tensors)
Slice and slice methods of arrays in JS
Module 5 (microblog comments)
Using CMD (command prompt) to install MySQL & configure the environment
Seven competencies required by architects
浏览器的5种观察器
Write regular isosceles triangle and inverse isosceles triangle with for loop in JS
Geospatial search: implementation principle of KD tree
原生js---无限滚动
剑指Offer 第 2 天链表(简单)
Reload cuda/cudnn/pytorch
出手即不凡,这很 Oracle!
JVM参数解释






