-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnagramString.java
39 lines (30 loc) · 937 Bytes
/
AnagramString.java
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
public class AnagramString {
public static void main(String args[]) {
String a = "aab";
String b = "aba";
boolean isAnagram = false;
boolean visited[] = new boolean[b.length()];
if (a.length() == b.length()) ;
{
for (int i = 0; i < a.length(); i++) {
char c = a.charAt(i);
isAnagram = false;
for (int j = 0; j < b.length(); j++) {
if (b.charAt(j) == c && !visited[j]) {
visited[j]=true;
isAnagram = true;
break;
}
}
if (!isAnagram) {
break;
}
}
}
if (isAnagram) {
System.out.println("anagram");
} else {
System.out.println("not anagram");
}
}
}