Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
don't use "sorted" solution in Uncategorized category for Bigger Together by zwerkoff
from typing import List
def compare(first: int, second: int):
if first == second:
return True
first, second = str(first), str(second)
min_len = len(first) if len(first) <= len(second) else len(second)
for i in range(min_len):
if first[i] < second[i]:
return True
elif first[i] > second[i]:
return False
else:
continue
if len(first) != min_len:
first = first[min_len:]
else:
second = second[min_len:]
return compare(first, second)
def get_smaller(ints: list):
ints = ints.copy()
smaller = []
while ints:
first = ints[0]
for i in ints[1:]:
if not compare(first, i):
first = i
smaller.append(first)
ints.remove(first)
return int(''.join([str(i) for i in smaller]))
def get_bigger(ints: list):
ints = ints.copy()
smaller = []
while ints:
first = ints[0]
for i in ints[1:]:
if compare(first, i):
first = i
smaller.append(first)
ints.remove(first)
return int(''.join([str(i) for i in smaller]))
def bigger_together(ints: List[int]) -> int:
return get_bigger(ints) - get_smaller(ints)
Oct. 26, 2020