-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnagram
38 lines (32 loc) · 968 Bytes
/
Anagram
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
//Anagram
import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.stream.*;
class GFG {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0) {
String s1 = br.readLine();
String s2 = br.readLine();
Solution obj = new Solution();
if(obj.areAnagrams(s1, s2)) {
System.out.println("true");
}
else {
System.out.println("false");
}
System.out.println("~");
}
}
}
class Solution {
public static boolean areAnagrams(String s1, String s2) {
char[] s1Array = s1.toCharArray();
char[] s2Array = s2.toCharArray();
Arrays.sort(s1Array);
Arrays.sort(s2Array);
return Arrays.equals(s1Array, s2Array);
}
}