File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def pot_sums (self , sqr : str , target_val : int ) -> bool :
3
+ if not sqr :
4
+ return target_val == 0
5
+
6
+ return any (self .pot_sums (sqr [i + 1 :], target_val - int (sqr [:i + 1 ]))
7
+ for i in range (0 , len (sqr )))
8
+
9
+ def punishmentNumber (self , n : int ) -> int :
10
+ return sum (x ** 2 for x in range (1 , n + 1 ) if self .pot_sums (str (x ** 2 ), x ))
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def pot_sums (self , sqr : str , target_val : int ) -> bool :
3
+ if not sqr :
4
+ return target_val == 0
5
+
6
+ return any (self .pot_sums (sqr [i + 1 :], target_val - int (sqr [:i + 1 ]))
7
+ for i in range (0 , len (sqr )))
8
+
9
+
10
+ def punishmentNumber (self , n : int ) -> int :
11
+ output = 0
12
+ for i in range (1 , n + 1 ) :
13
+ sqr = i ** 2
14
+ if self .pot_sums (str (sqr ), i ) :
15
+ output += sqr
16
+
17
+ return output
You can’t perform that action at this time.
0 commit comments