3 ms·
Consider character sequences: [n, e, t] and [t, e, n]. If you'd want to know if the lists are equivalent (have the same characters, same number of times), then
by ignoramous 7y ago
Consider character sequences: [n, e, t] and [t, e, n]. If you'd want to know if the lists are equivalent (have the same characters, same number of times), then sorting them would make the comparison straight-forward since order doesn't matter.
See: https://leetcode.com/problems/valid-anagram/solution https://leetcode.com/problems/valid-anagram/solution
- mobilemidget 7y agoah yes but of course, probably did not have enough coffee yet when I read it :) thank you But then perhaps it is worth storing it sorted ( or as well if original value is important) and making it even faster?