0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

missingintegers python 個人メモ

Last updated at Posted at 2020-11-17

missingintegers

普通にやったらもちろんN**2で返ってくる。ので、おそらく普通のやり方らしいが、フラグを作ってそこを積算的に立てていく。と一周+最後の判別ですむ(サイズ(N)で住む)

def solution(A):
    A = sorted(A)
    B = [i for i in A if (0 < i) and (i <= len(A))]
    tester = [0] * len(A)
    for i in B:
        tester[i-1] +=1
    try:
        return tester.index(0) + 1
    except:
        return len(B)+1
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?