Problem
Java
HashMap
1 | class Solution { |
Submission Detail
- 34 / 34 test cases passed.
- Runtime: 12 ms, faster than 22.04% of Java online submissions for Valid Anagram.
- Memory Usage: 40.6 MB, less than 28.82% of Java online submissions for Valid Anagram.
Sorting
© 20+ basic Algorithms Problems from Coding Interviews 16. Write Algorithms to Check if Two String are Anagram
One trick to solve this problem is to sort the character array and check if they are the same or not.
1 | class Solution { |
Submission Detail
- 34 / 34 test cases passed.
- Runtime: 4 ms, faster than 51.35% of Java online submissions for Valid Anagram.
- Memory Usage: 42.2 MB, less than 9.92% of Java online submissions for Valid Anagram.
leetcode solution - Hash Table
It seemed that no 0ms solution by java.
1 | class Solution { |
Submission Detail
- 34 / 34 test cases passed.
- Runtime: 3 ms, faster than 79.53% of Java online submissions for Valid Anagram.
- Memory Usage: 39.4 MB, less than 84.32% of Java online submissions for Valid Anagram.