How to check if a specific digit is in an integer

前端 未结 5 1036
我在风中等你
我在风中等你 2020-12-11 21:58

I want to check if, for example, the digit \'2\' is in 4059304593. My aim is to then check if there are any of the digits 1-9 not in my integer. This is what I have tried:

5条回答
  •  旧巷少年郎
    2020-12-11 22:21

    L = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    j = 0
    nL = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    n = 1004 #number
    while n:
        i = n%10
        nL[i] = 1
        n //= 10
    

    OUT

    nL = [1, 1, 0, 0, 1, 0, 0, 0, 0, 0]

    Explanation: if nL[i] is 1, then the i-th digit is in n

提交回复
热议问题