File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+
4+ class Solution :
5+ def combinationSum (self , candidates : List [int ], target : int ) -> List [List [int ]]:
6+ result = [[[] for _ in range (target + 1 )] for _ in range (len (candidates ))]
7+
8+ for index in range (len (candidates )):
9+ num = candidates [index ]
10+ for subTarget in range (1 , target + 1 ):
11+ maxUseCount = subTarget // num
12+ for useCount in range (0 , maxUseCount + 1 ):
13+ subSubTarget = subTarget - num * useCount
14+ if subSubTarget == 0 :
15+ result [index ][subTarget ].append ([num ] * useCount )
16+ else :
17+ for item in result [index - 1 ][subSubTarget ]:
18+ result [index ][subTarget ].append (item + [num ] * useCount )
19+
20+ return result [len (candidates ) - 1 ][target ]
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def hammingWeight (self , n : int ) -> int :
3+ binaryString = bin (n )[2 :]
4+ return list (binaryString ).count ("1" )
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def isPalindrome (self , s : str ) -> bool :
3+ left = 0
4+ right = len (s ) - 1
5+
6+ while left < right :
7+ while left < len (s ) - 1 and not s [left ].isalnum ():
8+ left += 1
9+ while right > 0 and not s [right ].isalnum ():
10+ right -= 1
11+
12+ if left >= right :
13+ return True
14+ elif s [left ].lower () != s [right ].lower ():
15+ return False
16+ else :
17+ left += 1
18+ right -= 1
19+
20+ return True
You can’t perform that action at this time.
0 commit comments