leetcode242 Valid Anagram

lc242 Valid Anagram

Direct statistical occurrences of each letter can be

 1 class Solution {
 2     public boolean isAnagram(String s, String t) {
 3         if(s.length() != t.length())
 4             return false;
 5         int[] count = new int[256];
 6         
 7         for(char i : s.toCharArray()){
 8             count[i]++;
 9         }
10         
11         for(char i : t.toCharArray()){
12             if(--count[i] < 0)
13                 return false;   
14         }
15         
16         return true;
17     }
18 }

 

Guess you like

Origin www.cnblogs.com/hwd9654/p/10958749.html