forked from QuantSgh/coding_solution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNon Repeating Character
More file actions
63 lines (46 loc) · 966 Bytes
/
Non Repeating Character
File metadata and controls
63 lines (46 loc) · 966 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
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
//Function to find the first non-repeating character in a string.
char nonrepeatingCharacter(string S)
{
//Your code here
for(int i=0;i<S.length();i++)
{
int c=0;
for(int j=0;j<S.length();j++)
{
if(S[i]==S[j])
{
c++;
}
if(c>1)
break;
}
if(c==1)
return S[i];
}
return '$';
}
};
// { Driver Code Starts.
int main() {
int T;
cin >> T;
while(T--)
{
string S;
cin >> S;
Solution obj;
char ans = obj.nonrepeatingCharacter(S);
if(ans != '$')
cout << ans;
else cout << "-1";
cout << endl;
}
return 0;
}
// } Driver Code Ends