Skip to content

Commit 0d7824f

Browse files
authored
Create IsAnagramBruteForce.java
Brute force solution for checking whether a string is an anagram
1 parent d0d04a5 commit 0d7824f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

IsAnagramBruteForce.java

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
public boolean isAnagramBruteForce(String s, String t) {
2+
3+
Set<Integer> index = new HashSet<>();
4+
index.add(-1);
5+
6+
if(s.length()!=t.length()){
7+
8+
return false;
9+
}
10+
11+
int size = s.length();
12+
13+
for(int i =0;i<size;i++){
14+
15+
char frstWordChar= s.charAt(i);
16+
int flag=0;
17+
18+
for(int j =0;j<size;j++){
19+
20+
if(t.charAt(j)==frstWordChar && index.contains(j)==false){
21+
22+
index.add(j);
23+
flag=1;
24+
break;
25+
}
26+
27+
}
28+
29+
if(flag==0){
30+
31+
return false;
32+
}
33+
34+
}
35+
36+
return true;
37+
38+
}

0 commit comments

Comments
 (0)