Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8befc57

Browse files
author
Philip Guo
committed
bah
1 parent aa2989d commit 8befc57

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

questions/remove-dups.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Name:
2+
Remove duplicate characters
3+
4+
Question:
5+
Write a function to return a new string that contains the contents of
6+
the input string with all duplicates removed.
7+
8+
Hint:
9+
Think about using a set to keep track of already-seen characters.
10+
11+
Solution:
12+
Iterate through the input string and keep already-seen characters in a
13+
set. If a character hasn't been seen yet, then append it to an output
14+
list. Finally convert the list into a string using "''.join()" and then
15+
return it.
16+
17+
Skeleton:
18+
19+
def removeDups(s):
20+
# write your solution code here
21+
22+
// # Example solution:
23+
// def removeDups(s):
24+
// seen = set()
25+
// out = []
26+
// for c in s:
27+
// if c not in seen:
28+
// out.append(c)
29+
// seen.add(c)
30+
// return ''.join(out)
31+
32+
Test:
33+
input = "AAAABBBBB"
34+
result = removeDups(input)
35+
36+
Expect:
37+
result = "AB"
38+
39+
Test:
40+
input = "Hello World"
41+
result = removeDups(input)
42+
43+
Expect:
44+
result = "Helo Wrd"
45+
46+
Test:
47+
input = "Hello World"
48+
result = removeDups(input)
49+
50+
Expect:
51+
result = "Helo Wrd"
52+
53+
Test:
54+
input = "alibaba"
55+
result = removeDups(input)
56+
57+
Expect:
58+
result = "alib"
59+
60+
Test:
61+
input = "abcdefg"
62+
result = removeDups(input)
63+
64+
Expect:
65+
result = "abcdefg"
66+

0 commit comments

Comments
 (0)