Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MinSomai/38e27506a1facb7d571b6d5c0dc63485 to your computer and use it in GitHub Desktop.
Save MinSomai/38e27506a1facb7d571b6d5c0dc63485 to your computer and use it in GitHub Desktop.
Java | Java Anagrams - Hackerrank.java
import java.util.Scanner;
public class Solution {
static boolean isAnagram(String a, String b) {
if(a.length() != b.length()){
return false;
}
a = a.toLowerCase();
b = b.toLowerCase();
char[] temp = b.toCharArray();
for (Character c : a.toCharArray()) {
for(int i = 0; i < temp.length; i++){
if(c == temp[i]){
temp[i] = '0';
break;
}
}
}
for(Character c : temp){
if(c != '0'){
return false;
}
}
// Printing content of array
return true;
}
public static void main(String[] args) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment