-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringAnagram
More file actions
45 lines (42 loc) · 1.06 KB
/
StringAnagram
File metadata and controls
45 lines (42 loc) · 1.06 KB
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
40
41
42
43
44
45
/*
Find that which character is missing in input string
*/
#include <iostream>
using namespace std;
int main() {
// your code goes here
string s;
cin>>s;
bool a[26] = {}
for(int i = 0; i<26; i++){
a[s[i]-'a'] = 1; //a[97-97]=1, a[98-97]=1;...so on
}
for(int i = 0; i<26; i++){
if(a[i]!=1){
return (char)(s[i+'a']);
}
}
return 0;
}
//JAVA SOLUTION TO CHECK IF TWO STRINGS ARE ANAGRAM OR NOT
static boolean isAnagram(String a, String b) {
// Complete the function
a = a.toLowerCase();
b = b.toLowerCase();
// System.out.println(a);
// System.out.println(b);
int bool1[] = new int[26];
int bool2[] = new int[26];
for(int i = 0; i<a.length(); i++){
bool1[a.charAt(i)-'a']++; //a[97-97]=1, a[98-97]=1;...so on
}
for(int i = 0; i<b.length(); i++){
bool2[b.charAt(i)-'a']++;
}
for(int i = 0; i<26; i++){
if(bool1[i]!=bool2[i]){
return false;
}
}
return true;
}