【每日一题20220221】+1列表

:woman_mage: 给定一个数字列表,其中每个元素都是正整数。请编写一个函数,将列表整体所代表的数字加1,然后返回成新列表。

示例:
输入:[2, 3, 9],输出:[2, 4, 0]

题目难度:简单
题目来源:CodeWars:+1 Array

def solution(nums: list) -> list:
    # your code here

assert solution([2,3,9]) == [2,4,0]
assert solution([4,3,2,5]) == [4,3,2,6]
def solution(nums: list) -> list:
    # your code here
    return [int(i) for i in str(int(''.join([str(i) for i in nums])) + 1)]


assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]
def solution(nums:list) -> list:
    return [int(i) for i in str(int("".join(str(i) for i in nums))+1)]

assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]
def solution(nums: list) -> list:
    return eval('[' + ','.join(str(int(''.join([str(num) for num in nums])) + 1)) + ']')


assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]

a =
for i in range(0,len(nums)):
a.append(int(nums.pop(0))+1)
return a

def solution(nums: list) -> list:
    str_num = ""
    list_num = []
    
    for i in nums:
        str_num += "".join(str(i))
    int_num = int(str_num) + 1
    
    for j in str(int_num):
        list_num.append(int(j))
    return list_num


assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]
assert solution([9, 9, 9, 9]) == [1, 0, 0, 0, 0]
def solution(nums: list) -> list:
    return [int(i) for i in (str(int(''.join([str(i) for i in nums])) + 1))]


assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]

def solution(num: list) -> list:
    new_str = "".join(list(map(str, num)))
    return [int(x) for x in str(int(new_str) + 1)]

assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]

image

public static int[] solution(int[] nums){
        for(int i=nums.length-1;i>-1;i--){
            nums[i]+= 1;
            if(nums[i]==10) {
                nums[i] = nums[i]%10;
            } else {
                break;
            }
        }
        return nums;
    }

def solution(nums) :
datas = int(’’.join([str(x) for x in nums]))+1
return [x for x in str(datas)]

    def solution(nums: list) -> list:
        return [int(i) for i in (str(int(''.join([str(i) for i in nums])) + 1))]
def solution(nums: list) -> list:
    str_res = str(int(''.join([str(nums[i]) for i in range(len(nums))])) + 1)
    return [int(str_res[i]) for i in range(len(str_res))]


assert solution([2, 3, 9]) == [2, 4, 0]
assert solution([4, 3, 2, 5]) == [4, 3, 2, 6]