aboutsummaryrefslogtreecommitdiffstats
path: root/645
diff options
context:
space:
mode:
Diffstat (limited to '645')
-rwxr-xr-x645/main.py28
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()