-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNon repeating character.py
More file actions
47 lines (36 loc) · 875 Bytes
/
Copy pathNon repeating character.py
File metadata and controls
47 lines (36 loc) · 875 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
class Solution:
def nonrepeatingCharacter(self, s):
dic = {}
for i in s:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
for i in s:
if dic[i] == 1:
return i
return "$"
# {
# 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