Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c18cc14

Browse files
author
Amogh Singhal
authored
Update first_non_repeating.py
1 parent ce7bde1 commit c18cc14

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎first_non_repeating.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,29 @@ def first_non_repeating(input_string):
1414
break
1515

1616
return flag
17+
18+
# lesser time complexity
19+
# more space complexity
20+
# obvious space-time trade-off
21+
def first_non_repeating_v2(input_string):
22+
23+
flag = None
24+
repeating = []
25+
non_repeating = []
26+
27+
for char in input_string:
28+
if char in non_repeating:
29+
non_repeating.remove(char)
30+
repeating.append(char)
31+
else:
32+
non_repeating.append(char)
33+
34+
if len(non_repeating) == 0:
35+
pass
36+
else:
37+
flag = non_repeating[0]
38+
39+
return flag
1740

1841

1942
result = first_non_repeating("djebdedbekfrnkfnduwbdwkd")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /