Skip to content

Commit 93a76f5

Browse files
authored
Create maximum-sum-of-two-numbers.py
1 parent 1af74e6 commit 93a76f5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

maximum-sum-of-two-numbers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)