Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution in Clear category for Friends by mindaugas.dadurkevicius
class Friends:
def __init__(self, connections):
self.connections =[]
for i in connections:
if i not in self.connections:
self.connections.append(i)
def add(self, connection):
if connection in self.connections:
return False
self.connections.append(connection)
return True
def remove(self, connection):
if connection not in self.connections:
return False
self.connections.remove(connection)
return True
def names(self):
self.ans = set()
for i in self.connections:
for i2 in i:
if i2 not in self.ans:
self.ans.add(i2)
return self.ans
def connected(self, name):
self.ans = set()
for i in self.connections:
if name in i:
self.temp = set(i)
self.temp.remove(name)
self.ans.update(self.temp)
return self.ans
Sept. 11, 2018
Comments: