60. Permutation Sequence
Problem Link class Solution: def getPermutation(self, n: int, k: int) -> str: fact = [1] * (n+1) for i in range(2, n+1): fact[i] = fact[i-1] * i res = '' numGroups = n digits = '123456789' ...
Search for a command to run...
Articles tagged with #algorithms
Problem Link class Solution: def getPermutation(self, n: int, k: int) -> str: fact = [1] * (n+1) for i in range(2, n+1): fact[i] = fact[i-1] * i res = '' numGroups = n digits = '123456789' ...
Problem Link Solution 1: DFS class Solution: def lastStoneWeightII(self, stones: List[int]) -> int: memo = dict() return self.helper(stones, 0, 0, 0, memo) def helper(self, stones, i, S1, S2, memo) -> int: if (i, S1, ...
Problem Link class Solution: def nthUglyNumber(self, n: int, a: int, b: int, c: int) -> int: left = 1 right = 2 * 10**9 while left < right: m = left + (right - left) // 2 cnt = self.count(a, b, c, m...
Problem Link class Solution: def openLock(self, deadends: List[str], target: str) -> int: # Find the shortest path: BFS if '0000' in deadends: return -1 queue = ['0000'] deadSet = set(deadends) ...
Problem Link class Solution: def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool: cnt = 0 pre = 0 for i in range(len(flowerbed)): if pre == 0 and flowerbed[i] == 0: if i == len(flowe...
Problem Link Solution 1 class Solution: def findCircleNum(self, isConnected: List[List[int]]) -> int: res = 0 for i in range(len(isConnected)): if isConnected[i][i] == 1: res += 1 self.d...