mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
Update data_structures/arrays/strings/anagram_checker.rb
This commit is contained in:
parent
6c785524fb
commit
3bc81b8195
1 changed files with 4 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue