both string length should equal for check anagram
public class AnagramDiff {
public static void main(String args[]) {
int count = 0;
String s1 = "spot";
String s2 = "poat";
int[] arr = new int[26];
for(int i=0;i<s1.length();i++) {
arr[s1.charAt(i)-'a']++;
}
for(int i=0;i<s2.length();i++) {
if(--arr[s2.charAt(i)-'a'] <0) {
count++;
}
}
System.out.println("number of manipulation required:"+count);
}
}
public class AnagramDiff {
public static void main(String args[]) {
int count = 0;
String s1 = "spot";
String s2 = "poat";
int[] arr = new int[26];
for(int i=0;i<s1.length();i++) {
arr[s1.charAt(i)-'a']++;
}
for(int i=0;i<s2.length();i++) {
if(--arr[s2.charAt(i)-'a'] <0) {
count++;
}
}
System.out.println("number of manipulation required:"+count);
}
}
No comments:
Post a Comment