Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SRM600 Div2 Medium bitのOR
class ORSolitaireDiv2:
def getMinimum(self, numbers, goal):
numbers = list(numbers)
goal_bin = str(bin(goal))[2:]
goal_bin = list(reversed(goal_bin))
counter = [0 for _ in goal_bin]
numbers = [num for num in numbers if num <= goal]
for num in numbers:
num_bin = list(reversed(str(bin(num))[2:]))
isInvalid = False
for i, n in enumerate(num_bin):
if goal_bin[i] == '0' and num_bin[i] == '1':
isInvalid = True
if isInvalid:
for i, n in enumerate(num_bin):
if n == '1':
counter[i] += 1
counter = [c for i, c in enumerate(counter) if goal_bin[i] == '1' ]
return min(counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.