Update data_structures/arrays/strings/anagram_checker.rb

This commit is contained in:
Vitor Oliveira 2021-03-31 18:37:57 -07:00 committed by GitHub
parent 6c785524fb
commit 3bc81b8195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,9 @@
#
# Approach 1: Sort and Compare
#
# Time Complexity: O(n log n)
# Complexity analysis:
#
# Time Complexity: O(n log n). Assume that n is the length of s, sorting costs O(n log n), and comparing two strings costs O(n). Sorting time dominates and the overall time complexity is O(n log n).
#
def is_anagram(s, t)
return false if s.length != t.length
@ -39,4 +41,4 @@ puts(is_anagram(s, t))
s = 'a'
t = 'ab'
puts(is_anagram(s, t))
# => false
# => false