【每日一题20220402】回文数字 #1.5

:mage:‍ 回文是指一段数字或者文本,正着读和倒着读都是相同的,例如2002,110011都是回文数字。请编写一个函数,接收2个数字n和m,找出大于数字n的m个有效回文数字,以列表的格式返回。如果n本身也是回文数字,那么也算其中一个。单个数字不被视为回文数字。

【示例】
输入:6, 4
输出:[11, 22, 33, 44]
解释:6自身不算回文数字,继续往后找。直到找到11、22、33和44,一共4个有效的回文数字为止。

题目难度:中等
题目来源:CodeWars-Numerical Palindrome #1.5

def solution(n: int, m: int)-> list:
    # your code here

assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]
def solution(n: int, m: int)-> list:
    result_list = []
    def get_num(num):
        if len(str(num))<=1:
            return False
        if str(num) == str(num)[::-1]:
            return num
    while n:
        if len(result_list)==m:
            return result_list
        if get_num(n):
            result_list.append(n)
        n += 1
assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]
def solution(n: int, m: int)-> list:
    # your code here
    res_list = []
    while n:
        if n < 10:
            n += 1
            continue
        if n == int(str(n)[::-1]):
            res_list.append(n)
        if len(res_list) == m:
            break
        n += 1
    return res_list

assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]

def solution(n: int, m: int)-> list:
# your code here
value =
i = 0
while len(value) < m:
k = n + i
if k == int((str(k)[::-1])) and k > 10:
value.append(k)
i += 1
return value

assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]

def solution(n, m):
    # your code here
    lt = []
    while n:
        if n < 9:
            n += 1
            continue
        if str(n) == str(n)[::-1]:
            lt.append(n)
            if len(lt) == m :
                return lt
        n += 1

assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]
def solution(n: int, m: int) -> list:
    r = []
    while True:
        if n == int(str(n)[::-1]) and n > 10:
            r.append(n)
            if len(r) == m:
                return r
        n += 1


assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]

def solution(n:int, m:int):
setDatas =
while n:
if len(setDatas) == 3:
return setDatas
if str(n) == str(n)[::-1]:
setDatas.append(n)
n += 1
assert solution(6, 4) == [11, 22, 33, 44]

def solution(n: int, m: int)-> list:
    result=list()
    while True and len(result)>m:
        if n>9 and str(n)[::-1]==str(n):
            result.append(n)
            n+=1
        else:
            n+=1
    return result


def solution(n: int, m: int)-> list:
    list_num=[]
    while len(list_num)<m:
        if n<10:
            n=10
        if n==int((str(n)[::-1])):
            list_num.append(n)
        n=n+1
    return list_num
def solution(n, m):
    a = []
    while len(a) < m:
        if n > 10:
            if n == int(str(n)[::-1]):
                a.append(n)
        n = n + 1
    return a

def solution(n: int,m: int) → list:
  lst =
  while True:
    if n>10 and str(n) == str(n)[::-1]:
      lst.append(n)
    n = n+1
    if len(lst) == m:
      break
  return lst

def fun(num: int) -> bool:
    nums_str = str(num)
    if nums_str == ''.join(reversed(nums_str)):
        return True
    else:
        return False


def solution(n: int, m: int) -> list:
    i = 0
    result = []
    while i < m:
        if n < 10:
            n = 10
        if fun(n):
            i += 1
            result.append(n)
        n += 1
    return result


assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]

def solution(n: int, m: int) → list:
# your code here
count = 0
reslut =
while True:
if str(count) == str(count)[::-1] and len(str(count)) > 1 and count >= n:
# print(count)
reslut.append(count)
count += 1
if len(reslut) >= m:
return reslut
else:
count += 1

image

def solution(n: int, m: int) -> list:
    result_list = []

    def get_num(num):
        if len(str(num)) <= 1:
            return False
        if str(num) == str(num)[::-1]:
            return num

    while n:
        if len(result_list) == m:
            return result_list
        if get_num(n):
            result_list.append(n)
        n += 1
def solution(n: int, m: int)-> list:
    res_list=[]
    if len(str(n))==1:
        n=11
    num=n
    time=0
    while time<m:
        if str(num)==str(num)[-1::-1]:
            time+=1
            res_list.append(num)
        num+=1
    return res_list

assert solution(6, 4) == [11, 22, 33, 44]
assert solution(59, 3) == [66, 77, 88]
assert solution(101, 2) == [101, 111]