def test_single_number(self): random.seed('test') self.assertEqual(0, single_number([1, 0, 2, 1, 2, 3, 3])) self.assertEqual(101, single_number([101])) single = random.randint(1, 100000) nums = [random.randint(1, 100000) for _ in range(1000)] nums *= 2 # nums contains pairs of random integers nums.append(single) random.shuffle(nums) self.assertEqual(single, single_number(nums))
def test_single_number(self): arr = [] for i in range(1000): arr.append(i) arr.append(i) random.shuffle(arr) rand_index = random.randint(0, len(arr)) num = arr.pop(rand_index) self.assertEqual(single_number(arr), num)
def find_difference(s, t): return chr(single_number([ord(ch) for ch in s + t]))
def test_single_number(self): self.assertEqual(single_number([2, 2, 1]), 1) self.assertEqual(single_number([4, 1, 2, 1, 2]), 4) self.assertEqual(single_number([1]), 1)