Skip to content

Commit d0d04a5

Browse files
authored
Create 13.AnagramsBruteForceSolution.java
T(N) = O(N^2)
1 parent d92c215 commit d0d04a5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

13.AnagramsBruteForceSolution.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)