Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
#include <stdarg.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
#define CONVERSION_TRIGGER '%' | |
#define MINUS_SIGN '-' | |
#define DIGITS "0123456789abcdef" | |
#define OCTAL 8 | |
#define DECIMAL 10 | |
#define HEXADECIMAL 16 |
This file contains 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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <stddef.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <stdbool.h> | |
#define READLINE_READ_SIZE 512 | |
#define NEWLINE '\n' |
This file contains 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
from math import sqrt | |
def numSquares(target): | |
squares = [n ** 2 for n in range(1, int(sqrt(target)) + 1)] | |
level = 0 | |
remainders = {target} | |
while True: | |
level += 1 | |
next_remainders = set() | |
for remainder in remainders: | |
for square in squares: |
This file contains 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
import functools | |
class StackQueue: | |
def __init__(self): | |
self.main = [] | |
self.aux = [] | |
def __repr__(self): | |
return f'StackQueue(self.main={self.main}, self.aux={self.aux})' | |
This file contains 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 spiral_order(matrix): | |
output = [] | |
if matrix is None: | |
return output | |
# Copy the matrix to avoid modifying the input | |
matrix = [line[:] for line in matrix] | |
while matrix: | |
output.extend(matrix[0]) | |
del matrix[0] | |
# Transpose the matrix, and then reverse its rows |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 n_queens(n): | |
def solve(): | |
i = len(columns) | |
if i == n: | |
solutions.append([f"{'.' * col}Q{'.' * (n - col - 1)}" for col in columns]) | |
return | |
for j in range(n): | |
if is_legal(i, j): | |
add_candidate(i, j) | |
solve() |
This file contains 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
from itertools import chain | |
from collections import namedtuple | |
from heapq import heappop, heappush | |
# The heapq module maintains a min-heap invariant, so we have to use | |
# the negative of the buildings' height because we'd like a max-heap | |
Building = namedtuple('Building', ['neg_height', 'end']) | |
Line = namedtuple('Line', ['start', 'height']) | |
# buildings[i] = [left_i, right_i, height_i] | |
def get_skyline(buildings): |
This file contains 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
/* char_map.h */ | |
#ifndef CHAR_MAP_H | |
#define CHAR_MAP_H | |
typedef struct char_map CharMap; | |
struct char_map { | |
char wall; | |
char corridor; | |
char path; | |
char entrance; |
OlderNewer