Skip to content

Commit 02b66c1

Browse files
author
batbrain7
committed
feat: add string related algorithms
1 parent 0161400 commit 02b66c1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Strings/Anagram.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Scanner;
2+
3+
public class Anagram {
4+
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
8+
int t = sc.nextInt();
9+
String s1,s2;
10+
int[] arr,arr1;
11+
12+
for(int i=0;i<t;i++) {
13+
int c = 0;
14+
s1 = sc.next();
15+
s2 = sc.next();
16+
if(s1.length() == s2.length()) {
17+
arr = new int[26];
18+
arr1 = new int[26];
19+
for(int j=0;j<s1.length();j++) {
20+
arr[s1.charAt(j) - 'a']++;
21+
arr1[s2.charAt(j) - 'a']++;
22+
}
23+
for(int j=0;j<arr.length;j++) {
24+
if(arr[j] != arr1[j]) {
25+
c = 1;
26+
break;
27+
}
28+
}
29+
} else {
30+
c = 1;
31+
}
32+
if(c == 1) {
33+
System.out.println("NO");
34+
} else {
35+
System.out.println("YES");
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)