【每日一题20220214】数字化

:woman_mage:给定一个非负整数n,请编写一个函数,返回由其中所有单个数字组成的列表。

示例:
输入:123,输出:[1, 2, 3]
输入:1,输出:[1]

题目难度:简单
题目来源:CodeWars:Digitize

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

assert solution(123) == [1, 2, 3]
assert solution(1) == [1]
assert solution(1230) == [1, 2, 3, 0]
assert solution(8675309) == [8,6,7,5,3,0,9]
def solution(n: int) -> list:
    return [int(x) for x in str(n)]

def solution(n: int) -> list:
    # your code here
    return [int(i) for i in str(n)]
def solution(n: int) -> list:
    return [int(i) for i in list(str(n))]


assert solution(123) == [1, 2, 3]
assert solution(1) == [1]
assert solution(1230) == [1, 2, 3, 0]
assert solution(8675309) == [8, 6, 7, 5, 3, 0, 9]
def solution(n: int) -> list:
    return [int(num) for num in str(n)]

assert solution(123) == [1, 2, 3]
assert solution(1) == [1]
assert solution(1230) == [1, 2, 3, 0]
assert solution(8675309) == [8,6,7,5,3,0,9]
def solution(n: int) -> list:
    return [int(i) for i in str(n)]

assert solution(123) == [1, 2, 3]
assert solution(1) == [1]
assert solution(1230) == [1, 2, 3, 0]
assert solution(8675309) == [8,6,7,5,3,0,9]
def solution(n: int) -> list:
    return [int(i) for i in str(n)]
    public static List<Integer> splitNum(int num){
        String str_num=String.valueOf(num);
        List<Integer> list_num=new ArrayList<>();
        for (int i = 0; i < str_num.length(); i++) {
            list_num.add(Integer.parseInt(str_num.substring(i,i+1)));
        }
        return list_num;
    }