Last active
December 31, 2017 15:43
-
-
Save amulyakashyap09/0ec512c588d8ab7c8b836489afad6eaa to your computer and use it in GitHub Desktop.
Set .add() | hackerrank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# METHOD 1 | |
n = int(input())#take input in n | |
a = set() | |
for i in range(n): | |
ci = input() | |
if ci not in a: | |
a.add(ci) | |
print(len(a)) | |
# METHOD 2 | |
n = int(input()) | |
a = list() | |
for i in range(n): | |
ci = input() | |
indexValue = a.index(ci) if ci in a else -1 | |
if indexValue == -1: | |
a.append(ci) | |
print(len(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment