목록전체 글 (95)
IT_World
class Solution: def subsets(self, nums: List[int]) -> List[List[int]]: result = [] def dfs(index,path) : result.append(path) for i in range(index, len(nums)): dfs(i + 1,path + [nums[i]]) dfs(0,[]) return result
class Solution: def generateParenthesis(self, n: int) -> List[str]: ''' type n = int ''' self.res = [] self.helper("",n,n) return self.res def helper(self, current,left, right) : if right == 0: self.res.append(current) else : if left > 0: self.helper(current + "(", left-1, right) if left < right : self.helper(current + ")", left, right-1)
class Solution: def mySqrt(self, x: int) -> int: return int(x**(1/2))
class Solution: def addBinary(self, a: str, b: str) -> str: return format(int(a,2) + int(b,2),'b')
class Solution: def maxSubArray(self, nums: List[int]) -> int: bstsum = -sys.maxsize crsum = 0 for num in nums : crsum = max(num, num + crsum) bstsum = max(crsum, bstsum) return bstsum
class Solution: def strStr(self, haystack: str, needle: str) -> int: if len(needle) =="" : return 0 else : return haystack.find(needle)
class Solution: def removeDuplicates(self, nums: List[int]) -> int: nums_len = len(nums) cnt = 0 for i in range(1, nums_len): if nums[cnt] != nums[i]: cnt = cnt + 1 nums[cnt] = nums[i] return cnt + 1