forked from hcientist/OnlinePythonTutor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-dups.txt
More file actions
76 lines (55 loc) · 1.22 KB
/
remove-dups.txt
File metadata and controls
76 lines (55 loc) · 1.22 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Name:
Remove duplicate characters
Question:
Write a function to return a new string that contains the contents of
the input string (in the original order) with all duplicate characters
removed.
Hint:
Think about using a set to keep track of already-seen characters.
Solution:
Iterate through the input string and keep already-seen characters in a
set. If a character hasn't been seen yet, then append it to an output
list. Finally convert the list into a string using "''.join()" and then
return it.
Skeleton:
def removeDups(s):
# write your solution code here
// # Example solution:
// def removeDups(s):
// seen = set()
// out = []
// for c in s:
// if c not in seen:
// out.append(c)
// seen.add(c)
// return ''.join(out)
Test:
input = "AAAABBBBB"
result = removeDups(input)
Expect:
result = "AB"
Test:
input = "Hello World"
result = removeDups(input)
Expect:
result = "Helo Wrd"
Test:
input = "Hello World"
result = removeDups(input)
Expect:
result = "Helo Wrd"
Test:
input = "alibaba"
result = removeDups(input)
Expect:
result = "alib"
Test:
input = "abcdefg"
result = removeDups(input)
Expect:
result = "abcdefg"
Test:
input = ""
result = removeDups(input)
Expect:
result = ""