We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1af74e6 commit 93a76f5Copy full SHA for 93a76f5
maximum-sum-of-two-numbers.py
@@ -0,0 +1,31 @@
1
+from typing import (
2
+ List,
3
+)
4
+
5
+class Solution:
6
+ """
7
+ @param a: An Integer array
8
+ @return: returns the maximum sum of two numbers
9
10
+ def maximum_sum(self, a: List[int]) -> int:
11
+ # write your code here
12
+ r = -1
13
+ di = {}
14
+ for i in a:
15
+ d = 0
16
+ j = i
17
+ while j > 0:
18
+ d += j % 10
19
+ j = int(j / 10)
20
+ if d not in di:
21
+ di[d] = []
22
+ di[d].append(i)
23
+ for k, v in di.items():
24
+ if len(v) >= 2:
25
+ v.sort()
26
+ s = v[-1] + v[-2]
27
+ if s > r:
28
+ r = s
29
+ return r
30
31
+# medium: https://www.lintcode.com/problem/1604/
0 commit comments