Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public boolean isAnagram(String s, String t) {
- char[] sa = s.toCharArray();
- char[] ta = t.toCharArray();
- Arrays.sort(sa);
- Arrays.sort(ta);
- return Arrays.equals(sa, ta);
- }
- }
- class Solution {
- public boolean isAnagram(String s, String t) {
- int[] freq = new int[26];
- for (int i = 0; i < s.length(); i++) freq[s.charAt(i) - 'a']++;
- for (int i = 0; i < t.length(); i++) freq[t.charAt(i) - 'a']--;
- for (int f : freq) if (f != 0) return false;
- return true;
- }
- }
- class Solution {
- public boolean isAnagram(String s, String t) {
- int[] freq = new int[26];
- for (char c : s.toCharArray()) freq[c - 'a']++;
- for (char c : t.toCharArray()) freq[c - 'a']--;
- for (int f : freq) if (f != 0) return false;
- return true;
- }
- }
- class Solution {
- public boolean isAnagram(String s, String t) {
- int[] freq = new int[256];
- for (char c : s.toCharArray()) freq[c]++;
- for (char c : t.toCharArray()) freq[c]--;
- for (int f : freq) if (f != 0) return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement