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
from sys import getsizeof | |
from timeit import timeit | |
bitset = 0 | |
N = 100000 | |
def populate_bitset(): | |
global bitset |
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 backspaceCompare(self, *all_strings) -> bool: | |
def next_index(s: str, i: int) -> int: | |
""" | |
Get the index of the next undeleted letter | |
@param R: str string | |
@param i: index | |
@return: current letter index | |
""" |
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 backspaceCompare(self, S: str, T: str) -> bool: | |
def next_index(R: str, i: int) -> int: | |
""" | |
Get the index of the next undeleted letter | |
@param R: str string | |
@param i: index | |
@return: current letter index | |
""" |
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
# <editor-fold desc="Fast IO"> | |
# !/usr/bin/env python | |
from __future__ import division, print_function | |
import os | |
import random | |
import sys | |
from io import BytesIO, IOBase | |
if sys.version_info[0] < 3: |
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 isValid(node, floor, ceiling): | |
if not node: | |
return True | |
if not floor < node.val < ceiling: | |
return False | |
return isValid(node.left, floor, node.val) and isValid(node.right, node.val, ceiling) |
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 corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]: | |
prefix_sum = [0] * (n + 1) | |
# 1. Build prefix sum array | |
# for booking [1, 3, 5] and n = 5 prefix sum array: | |
# [0, 0, 0, 0, 0] -> [5, 0, 0, -5, 0, 0] | |
for lo, hi, seats in bookings: | |
prefix_sum[lo - 1] += seats |
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
import sys | |
def read_line(): | |
return sys.stdin.readline().split() | |
def read_int_iter(): | |
return map(int, read_line()) |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
const ( | |
N = 20 |
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 oswalk(dirname): | |
if not os.path.isdir(dirname): | |
return | |
names = os.listdir(dirname) | |
filenames = [] | |
dirnames = [] | |
dirpaths = [] |
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 mark_island(grid, i, j): | |
if i >= 0 and j >= 0 and i < len(grid) and j < len(grid[i]) and grid[i][j] == 1: | |
grid[i][j] = 0 | |
mark_island(grid, i, j+1) | |
mark_island(grid, i+1, j) | |
mark_island(grid, i, j-1) | |
mark_island(grid, i-1, j) | |
def get_number_of_islands(grid): |
NewerOlder