In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-10-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to solve the problem of effective letter ectopic words in leetcode". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to solve the problem of effective letter ectopic words in leetcode".
Topic link
Https://leetcode-cn.com/problems/valid-anagram/
Topic description
Given the two strings s and t, write a function to determine whether t is a letter heteronym of s.
Example 1:
Input: s = "anagram", t = "nagaram" output: true
Example 2:
Input: s = "rat", t = "car" output: false
Description: you can assume that the string contains only lowercase letters.
Advanced: what if the input string contains unicode characters? Can you adjust your solution to deal with this situation?
The idea of solving the problem
Tags: hash mapping
First, determine whether the two strings are equal in length, and return false directly if they are not equal.
If equal, initialize the 26-letter hash table and traverse the strings s and t
S is responsible for increasing at the corresponding position, and t is responsible for decreasing at the corresponding position.
If the value of the hash table is 0, then both are letter ectopic words.
Graphic illustration
Code class Solution {public boolean isAnagram (String s, String t) {if (s.length ()! = t.length ()) return false; int [] alpha = new int [26]; for (int I = 0; I < s.length (); iCode+) {alpha [s.charAt (I) -'a'] + Alpha [t.charAt (I) -'a']--;} for (int item0
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: 0
*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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.