-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
58 lines (38 loc) · 1.12 KB
/
Copy pathMain.java
File metadata and controls
58 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.*;
public class Main {
public static boolean areAnagrams(String str1, String str2) {
if (str1.length() != str2.length()){
return false;
}
int count[] = new int[26];
for(char x:str1.toCharArray()){
count[x-'a']++;
}
for(char x : str2.toCharArray()){
count[ x - 'a']--;
}
for(int val : count){
if(val != 0){
return false;
}
}
return true;
}
// public void helper_function(){
// Scanner sc = new Scanner(System.in);
// int n;
// n = sc.nextInt();
// }
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String str1 = sc.nextLine();
String str2 = sc.nextLine();
if (areAnagrams(str1, str2)){
System.out.println("Anagrams");
}
else{
System.out.println("Not Anagrams");
}
sc.close();
}
}