This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def __init__(self, N, blacklist): | |
| blacklist.sort() | |
| self.N = N - len(blacklist) | |
| self.free_pairs = self.prep_free_pairs(N, blacklist) | |
| self.offsets = [0] | |
| for pair in self.free_pairs: | |
| self.offsets.append(pair[1] - pair[0] + 1) | |
| self.offsets[-1] += self.offsets[-2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def largestComponentSize(self, A): | |
| return self.figure_components(A, self.sieve()) | |
| def sieve(self): | |
| range_max = 100001 | |
| sieve_array = [-1] * range_max | |
| for i in range(2, range_max): | |
| for j in range(i, range_max, i): | |
| if sieve_array[j] == -1: sieve_array[j] = i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def removeStones(self, stones): | |
| t = [-1] * len(stones) | |
| xs, ys = {}, {} | |
| for i, p in enumerate(stones): | |
| x, y = p | |
| if x in xs: self.onion(xs[x], i, t) | |
| else: xs[x] = i | |
| if y in ys: self.onion(ys[y], i, t) | |
| else: ys[y] = i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| https://leetcode.com/problems/burst-balloons/description/ | |
| ''' | |
| class Solution: | |
| def maxCoins(self, nums): | |
| nums = [1, *nums, 1] | |
| return self.dp(0, len(nums) - 1, nums, {}) | |
| def dp(self, a, b, nums, memo): | |
| if abs(a - b) < 2: return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nums = [ "569815571556", "4938532894754", "1234567", "472844278465445" ] | |
| def get_lotter_nums_rec_helper(curr_num, curr_n, rem_str): | |
| if curr_num > 0 and curr_num < 60: | |
| lottery_nums = get_lottery_nums_rec(curr_n - 1, rem_str) | |
| if lottery_nums: | |
| return [curr_num] + lottery_nums | |
| def get_lottery_nums_rec(n, s): | |
| if n == 0 and s == '': return [' '] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nums = [ "569815571556", "4938532894754", "1234567", "472844278465445" ] | |
| def get_lotter_nums_rec_helper(curr_num, curr_n, rem_str): | |
| if curr_num > 0 and curr_num < 60: | |
| lottery_nums = get_lottery_nums_rec(curr_n - 1, rem_str) | |
| if lottery_nums: | |
| return [curr_num] + lottery_nums | |
| def get_lottery_nums_rec(n, s): | |
| if n == 0 and s == '': return [' '] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def callAll(): | |
| result = True | |
| result = A() and result | |
| result = B() and result | |
| # so on | |
| return result |
NewerOlder