diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-01-22 03:25:29 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-01-22 03:25:29 +0000 |
commit | 0d90ca6a269aeacd8462623596e820cc3274434f (patch) | |
tree | 67478306d611c8ae3403c007581d5fc8a7bffc06 /645 | |
parent | 907 (diff) | |
download | leetcode-0d90ca6a269aeacd8462623596e820cc3274434f.tar.gz leetcode-0d90ca6a269aeacd8462623596e820cc3274434f.zip |
645
Diffstat (limited to '645')
-rwxr-xr-x | 645/main.py | 28 |
1 files changed, 28 insertions, 0 deletions
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() |