Given two strings s and t, return true if t is an anagram of s, and false otherwise.
An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once.
1 <= s.length, t.length <= 5 * 10^4s and t consist of lowercase English letters.No developer has claimed the Java throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) {
return false;
}
var sCharToCount = new HashMap<Character, Integer>();
for (var character : s.toCharArray()) {
sCharToCount.put(character, sCharToCount.getOrDefault(character, 0) + 1);
}
var tCharToCount = new HashMap<Character, Integer>();
for (var character : t.toCharArray()) {
tCharToCount.put(character, tCharToCount.getOrDefault(character, 0) + 1);
}
return sCharToCount.equals(tCharToCount);
}
}
No developer has claimed the Python throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.# from collections import defaultdict
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t):
return False
s_char_to_count = defaultdict(int)
for char in s:
s_char_to_count[char] += 1
t_char_to_count = defaultdict(int)
for char in t:
t_char_to_count[char] += 1
return s_char_to_count == t_char_to_count
No developer has claimed the Javascript throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.var isAnagram = function (s, t) {
if (s.length != t.length) {
return false;
}
const sCharToCount = new Map()
const tCharToCount = new Map()
for (const char of s) {
sCharToCount.set(char, (sCharToCount.get(char) || 0) + 1)
}
for (const char of t) {
tCharToCount.set(char, (tCharToCount.get(char) || 0) + 1)
}
return _.isEqual(sCharToCount, tCharToCount)
};
No developer has claimed the C# throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.public class Solution
{
public bool IsAnagram(string s, string t)
{
if (s.Length != t.Length)
return false;
var sCharToCount = new Dictionary<char, int>();
var tCharToCount = new Dictionary<char, int>();
foreach (char character in s)
sCharToCount[character] = sCharToCount.GetValueOrDefault(character, 0) + 1;
foreach (char character in t)
tCharToCount[character] = tCharToCount.GetValueOrDefault(character, 0) + 1;
foreach (var entry in sCharToCount)
{
if (entry.Value != tCharToCount.GetValueOrDefault(entry.Key))
{
return false;
}
}
return true;
}
}
No developer has claimed the Go throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.import "reflect"
func isAnagram(s string, t string) bool {
if len(s) != len(t) {
return false
}
// Create frequency maps for both strings
sCharCount := make(map[rune]int)
for _, char := range s {
sCharCount[char]++
}
tCharCount := make(map[rune]int)
for _, char := range t {
tCharCount[char]++
}
return reflect.DeepEqual(sCharCount, tCharCount)
}
No developer has claimed the Ruby throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.def is_anagram(s, t)
return false if s.length != t.length
s_char_to_count = Hash.new(0)
t_char_to_count = Hash.new(0)
s.each_char do |char|
s_char_to_count[char] += 1
end
t.each_char do |char|
t_char_to_count[char] += 1
end
s_char_to_count == t_char_to_count
end
No developer has claimed the C++ throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
false directly.hash tables to store the statistics of the two strings respectively, with the key being the character and the value being the number of characters.hash tables to see if they are equal.class Solution {
public:
bool isAnagram(string s, string t) {
if (s.length() != t.length()) {
return false;
}
unordered_map<char, int> s_char_to_count;
for (char character : s) {
s_char_to_count[character]++;
}
unordered_map<char, int> t_char_to_count;
for (char character : t) {
t_char_to_count[character]++;
}
return s_char_to_count == t_char_to_count;
}
};
No developer has claimed the Rust throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Swift throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Kotlin throne for LeetCode #242 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.