In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces LeetCode how to solve the problem of effective letter ectopic words, the article is very detailed, has a certain reference value, interested friends must read it!
1. Title
Valid letter ectopic words
two。 Description
Given the two strings s and t, write a function to determine whether t is a letter heteronym of s.
Example 1:
Enter: s = "anagram", t = "nagaram"
Output: true
Example 2:
Enter: s = "rat", t = "car"
Output: false
3. First of all, the idea of length comparison, the difference is not followed by using an array of length 26 to represent the number of characters appearing in the string s plus the number of characters appearing in the string t minus 1 and finally judging whether the number of each lowercase letter is 0 or not. At this time, the traversal operation is mainly carried out, and the time complexity is 4. Implement public boolean isAnagram (String s, String t) {
/ / compare the length, but not if the length is different
If (s.length ()! = t.length ()) {
Return false
}
/ * an array of 26 is used to represent the number of occurrences of each character
* add 1 to the number of characters that appear in the string s
* the number of characters appearing in the string t minus 1
* finally determine whether the number of each lowercase letter is 0
, /
Int [] chaCount = new int [26]
For (int I = 0; I < s.length (); iTunes +) {
ChaCount [s.charAt (I) -'a'] + +
ChaCount [t.charAt (I) -'a']--
}
For (int item: chaCount) {
If (item! = 0) {
Return false
}
}
Return true
}
The above is all the content of the article "how to solve the problem of effective letter ectopic words in LeetCode". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 202
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.