luoheng
9/2/2019 - 6:50 AM

唯一重复的数

"""
input: 1-1000 put in 1001 array
output: the only repeated number

solution: sort
"""

import random


def findRepeatedNum(s):
    while s[s[0]] != s[0]:
        s[s[0]], s[0] = s[0], s[s[0]]
    return s[0]


def main():
    s = list(range(1, 1001))
    repeatNum = random.randint(1, 1000)
    s.append(repeatNum)
    random.shuffle(s)
    num = findRepeatedNum(s)
    print(num, repeatNum)


if __name__ == "__main__":
    main()