-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAnagram.java
More file actions
executable file
·33 lines (29 loc) · 887 Bytes
/
Copy pathAnagram.java
File metadata and controls
executable file
·33 lines (29 loc) · 887 Bytes
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
package com.vee.algorithms.recursion;
public class Anagram {
static int count = 0, space = 0;
public Boolean recursive(String a, String b) {
if (a.length() != b.length())
return false;
for(int x = 0; x < b.length(); x++)
if(a.charAt(0) == b.charAt(x))
return recursive(utilityFunction(a, 0), utilityFunction(b, x)) ;
return b.length() == 0;
}
String utilityFunction(String s, int j) {
char[] ret = new char[s.length() - 1];
space = space + s.length();
int d = 0;
for (int k =0; k<s.length();k++) {
if (k == j)
d = 1;
else
ret[k - d] = s.charAt(k);
count++;
}
return new String(ret);
}
public static void main(String args[]) {
System.out.println(new Anagram().recursive("abc", "cba"));
System.out.println(space + " " + count);
}
}