From 0d90ca6a269aeacd8462623596e820cc3274434f Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sun, 21 Jan 2024 22:25:29 -0500 Subject: 645 --- 645/main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 645/main.py diff --git a/645/main.py b/645/main.py new file mode 100755 index 0000000..7185fc8 --- /dev/null +++ b/645/main.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +class Solution: + def findErrorNums(self, nums): + counts = {} + one = 0 + for num in nums: + if num in counts: + counts[num] += 1 + one = num + else: + counts[num] = 1 + + total = len(nums) * (len(nums) + 1) // 2 + + return [one, total - sum(nums) + one] + + +def main(): + solution = Solution() + print(solution.findErrorNums([1, 2, 2, 4])) + print(solution.findErrorNums([1, 1])) + + +if __name__ == "__main__": + main() -- cgit v1.2.3