1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public boolean isAnagram(String s, String t) { int l1 = s.length(); int l2 = t.length(); if(l1 != l2) return false; int[] store = new int[26]; for(int i = 0, j = 0; i < l1 && j < l2;i++,j++){ store[s.charAt(i) - 'a']++; store[t.charAt(j) - 'a']--; } for(int value: store){ if(value != 0) return false; } return true; } }
|