Advertisement
md5kafka

Untitled

Oct 3rd, 2022
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.48 KB | None | 0 0
  1. class Solution {
  2.     public boolean isAnagram(String s, String t) {
  3.         if (s.length() != t.length()) {
  4.             return false;
  5.         }
  6.         int[] charCount = new int[256];
  7.         for(char a: s.toCharArray()) {
  8.             charCount[a]++;
  9.         }
  10.         for(char a:t.toCharArray()) {
  11.             charCount[a]--;
  12.         }
  13.         for(int i:charCount) {
  14.             if (i!=0) {
  15.                 return false;
  16.             }
  17.         }
  18.         return true;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement