-
Notifications
You must be signed in to change notification settings - Fork 0
/
nonRepeatingCharacter.py
52 lines (40 loc) · 1.09 KB
/
nonRepeatingCharacter.py
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
#User function Template for python3
class Solution:
#Function to find the first non-repeating character in a string.
def nonrepeatingCharacter(self,s):
#code here
ans = '$'
freq = dict()
for i in s:
if (i in freq.keys()):
freq[i] += 1
else:
freq[i] = 1
for i in s:
if freq[i]==1:
return i
return ans
#{
# Driver Code Starts
#Initial Template for Python 3
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
if __name__=='__main__':
t = int(input())
for i in range(t):
s=str(input())
obj = Solution()
ans=obj.nonrepeatingCharacter(s)
if(ans!='$'):
print(ans)
else:
print(-1)
# } Driver Code Ends