Created
May 8, 2021 14:01
-
-
Save MinSomai/38e27506a1facb7d571b6d5c0dc63485 to your computer and use it in GitHub Desktop.
Java | Java Anagrams - Hackerrank.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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