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 get_value(registers, value_or_register): | |
| try: | |
| return int(value_or_register) | |
| except ValueError as _: | |
| return registers.get(value_or_register, 0) | |
| def mov (registers, reg_to, y): | |
| registers[reg_to] = get_value(registers, y) | |
| return 1 | |
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 get_value(value_or_register, registers): | |
| try: | |
| return int(value_or_register) | |
| except ValueError as _: | |
| return registers.get(value_or_register, 0) | |
| def simple_assembler(program): | |
| registers = {} | |
| instruction_counter = 0 | |
| instructions = program |
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 uniquePaths(self, m: int, n: int) -> int: | |
| grid = [[1] * n for _ in range(m)] | |
| for i in range(1, m): | |
| for j in range(1, n): | |
| grid[i][j] = grid[i - 1][j] + grid[i][j - 1] | |
| return grid[-1][-1] | |
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
| WORD_END_CHAR = '$' | |
| class Trie: | |
| def __init__(self): | |
| """ | |
| Initialize your data structure here. | |
| """ | |
| self.trie = {} |
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 WordDictionary: | |
| def __init__(self): | |
| """ | |
| Initialize your data structure here. | |
| """ | |
| self.root = {} | |
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 Node(object): | |
| def __init__(self, value: str): | |
| self.value = value | |
| self.children = {} | |
| class WordDictionary: | |
| def __init__(self): |
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 get_skyline(buildings): | |
| result = [] | |
| xs = sorted([x for x1, x2, _ in buildings for x in (x1, x2)]) | |
| last_y = None | |
| for x in xs: | |
| y = max((y for x1, x2, y in buildings if x1 <= x < x2), default = 0) | |
| if y != last_y: | |
| result.append([x, y]) | |
| last_y = y | |
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 getSkyline(self, buildings: List[List[int]]) -> List[List[int]]: | |
| def divide_conquer(i, j): | |
| if j < i: | |
| return [] | |
| elif j == i: | |
| x1, x2, h = buildings[i] | |
| return [[x1, h], [x2, 0]] | |
| else: |
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 sol_equa(n): | |
| result = [] | |
| for y in range(n//2): | |
| f = n + 4*y*y | |
| if f > 0: | |
| x = f ** 0.5 | |
| #print(f"y = {y} f = {f} x = ={x}") | |
| if x % 1 == 0: | |
| result.append([int(x), y]) | |
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 solve(board): | |
| row = [set() for _ in range(9)] | |
| col = [set() for _ in range(9)] | |
| box = [set() for _ in range(9)] | |
| all_possible = set(range(1, 10)) | |
| for i in range(9): | |
| for j in range(9): | |
| if board[i][j] != 0: | |
| row[j].add(board[i][j]) |