Advertisement
exmkg

1-2

Jan 14th, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. class Solution {
  2.     public boolean isAnagram(String s, String t) {
  3.         char[] sa = s.toCharArray();
  4.         char[] ta = t.toCharArray();
  5.  
  6.         Arrays.sort(sa);
  7.         Arrays.sort(ta);
  8.  
  9.         return Arrays.equals(sa, ta);
  10.     }
  11. }
  12.  
  13.  
  14. class Solution {
  15.     public boolean isAnagram(String s, String t) {
  16.         int[] freq = new int[26];
  17.         for (int i = 0; i < s.length(); i++) freq[s.charAt(i) - 'a']++;
  18.         for (int i = 0; i < t.length(); i++) freq[t.charAt(i) - 'a']--;
  19.         for (int f : freq) if (f != 0) return false;
  20.         return true;
  21.     }
  22. }
  23.  
  24.  
  25.  
  26. class Solution {
  27.     public boolean isAnagram(String s, String t) {
  28.         int[] freq = new int[26];
  29.         for (char c : s.toCharArray()) freq[c - 'a']++;
  30.         for (char c : t.toCharArray()) freq[c - 'a']--;
  31.         for (int f : freq) if (f != 0) return false;
  32.         return true;
  33.     }
  34. }
  35.  
  36.  
  37.  
  38. class Solution {
  39.     public boolean isAnagram(String s, String t) {
  40.         int[] freq = new int[256];
  41.         for (char c : s.toCharArray()) freq[c]++;
  42.         for (char c : t.toCharArray()) freq[c]--;
  43.         for (int f : freq) if (f != 0) return false;
  44.         return true;
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement