-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_non_repeating.cpp
More file actions
55 lines (36 loc) · 969 Bytes
/
first_non_repeating.cpp
File metadata and controls
55 lines (36 loc) · 969 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "essentials.cpp"
string first_non_repeating(string test){
char *output=(char*)malloc(sizeof(char*)*256);
string hello="";
for(int i=0;i<test.length();i++){
output[test[i]]++;
}
for(int i=0;i<test.length();i++){
if(output[test[i]]==1){
hello+=test[i];
return hello;
}
}
cout<<"No First Non repeating character"<<endl;
}
int firstUniqChar(string s) {
char*count=new char[256];
for(int i=0;i<s.length();i++){
count[s[i]]++;
}
// cout<<"hello"<<endl;
for(int i=0;i<s.length();i++)
{
if(count[s[i]]==1){
return i;
}
}
return -1;}
int main(){
string test="itwqbtcdprfsuprkrjkausiterybzncbmdvkgljxuekizvaivszowqtmrttiihervpncztuoljftlxybpgwnjb";
string output1="";
output1+=first_non_repeating(test);
cout<<output1<<endl;
cout<<firstUniqChar(test)<<endl;
return 1;
}