MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / isAnagram

Method isAnagram

Java/valid-anagram.java:73–92  ·  view source on GitHub ↗
(String s, String t)

Source from the content-addressed store, hash-verified

71 // 3. Efficient approach using hashing
72 // Time: O(n) | Space: O(1) [because the table's size stays constant no matter how large n is]
73 public boolean isAnagram(String s, String t) {
74
75 int [] charCount = new int[128];
76
77 for (int i=0; i<s.length(); i++){
78 charCount[s.charAt(i)]++;
79 }
80
81 for (int i=0; i<t.length(); i++){
82 charCount[t.charAt(i)]--;
83 }
84
85 for (int i=0;i<128;i++){
86 if(charCount[i] != 0){
87 return false;
88 }
89 }
90
91 return true;
92 }
93}

Callers

nothing calls this directly

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected