newbison 发表于 2020-1-23 10:12:04

def func311(n):
    list1 = list(str(n))
    list2 = sorted(list(str(n)), reverse= True)
    i = 0
    while i < len(list1):
      if list1 >= list2:
            i += 1
            continue
      else:
            j = i+1
            while j < len(list1):
                if list1 < list2:
                  j += 1
                  continue
                else:
                  temp = list1
                  list1 = list1
                  list1 = temp
                  return int(''.join(list1))
    if i == len(list1) or j == len(list1):
      return n

776667 发表于 2021-3-22 11:42:08

from itertools import permutations

def fun311(x):
    x = str(x)
    combin_list = []
    for i in permutations(x):
      count = 0
      for j in range(len(i)):
            if x != i:
                count += 1
            if count > 2:
                break
      if count <= 2:
            combin_list.append(int(''.join()))
    return max(combin_list)
页: 1 [2]
查看完整版本: Python:每日一题 311