index
int64
repo_name
string
branch_name
string
path
string
content
string
import_graph
string
9,411
ESEGroup/Brasil
refs/heads/master
/app/models/agendamento.py
from django.db import models from app.models import Recurso, Usuario class Agendamento (models.Model): # no getters and setters please (http://dirtsimple.org/2004/12/python-is-not-java.html) usuario = models.ForeignKey(Usuario) recurso = models.ForeignKey(Recurso) inicio = models.DateTimeField() ...
{"/app/models/__init__.py": ["/app/models/usuario.py", "/app/models/recurso.py", "/app/models/agendamento.py", "/app/models/cadastro.py", "/app/models/notificador.py", "/app/models/notificador_cadastro.py", "/app/models/notificador_agendamento.py", "/app/models/busca.py", "/app/models/cadastro_recurso.py", "/app/models...
9,412
ESEGroup/Brasil
refs/heads/master
/app/models/cadastro_usuario.py
from django.db import models from app.models import Cadastro, Usuario from django.contrib.auth.models import User, Group from .settingsgroups import SettingsUserGroups class CadastroUsuario(Cadastro): notificador = None #NotificadorCadastro usuario = Usuario() usuarioTemplate = Usuario() solicitante ...
{"/app/models/__init__.py": ["/app/models/usuario.py", "/app/models/recurso.py", "/app/models/agendamento.py", "/app/models/cadastro.py", "/app/models/notificador.py", "/app/models/notificador_cadastro.py", "/app/models/notificador_agendamento.py", "/app/models/busca.py", "/app/models/cadastro_recurso.py", "/app/models...
9,413
ESEGroup/Brasil
refs/heads/master
/app/models/notificador.py
from django.db import models class Notificador(models.Model): # no getters and setters please (http://dirtsimple.org/2004/12/python-is-not-java.html) remetente = "<EMAIL DO SISTEMA>" mensagem = "" assunto = "" tipo_mensagem = 0 def enviarMensagem (): res = None ret...
{"/app/models/__init__.py": ["/app/models/usuario.py", "/app/models/recurso.py", "/app/models/agendamento.py", "/app/models/cadastro.py", "/app/models/notificador.py", "/app/models/notificador_cadastro.py", "/app/models/notificador_agendamento.py", "/app/models/busca.py", "/app/models/cadastro_recurso.py", "/app/models...
9,414
ESEGroup/Brasil
refs/heads/master
/app/models/notificador_agendamento.py
from django.db import models from app.models import Notificador class NotificadorAgendamento (Notificador): agendamento = None #Agendamento def construirMensagem (): return False class Meta: managed = False app_label = 'app'
{"/app/models/__init__.py": ["/app/models/usuario.py", "/app/models/recurso.py", "/app/models/agendamento.py", "/app/models/cadastro.py", "/app/models/notificador.py", "/app/models/notificador_cadastro.py", "/app/models/notificador_agendamento.py", "/app/models/busca.py", "/app/models/cadastro_recurso.py", "/app/models...
9,415
ESEGroup/Brasil
refs/heads/master
/app/migrations/0005_auto_20161119_1727.py
# -*- coding: utf-8 -*- # Generated by Django 1.10.3 on 2016-11-19 19:27 from __future__ import unicode_literals from django.conf import settings from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ migrations.swappable_depende...
{"/app/models/__init__.py": ["/app/models/usuario.py", "/app/models/recurso.py", "/app/models/agendamento.py", "/app/models/cadastro.py", "/app/models/notificador.py", "/app/models/notificador_cadastro.py", "/app/models/notificador_agendamento.py", "/app/models/busca.py", "/app/models/cadastro_recurso.py", "/app/models...
9,418
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/lights_controller.py
import logging import random import threading from time import sleep from lib.const import * log = logging.getLogger() job_statuses = dict() def animation_worker(led_strip, job, status, color, start, end): while job_statuses[job.name] == status: for x in range(0, 40): b = 1 - x*.02 led_strip.fill...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,419
jwolstenholme/pimp-my-ci
refs/heads/master
/lights_off.py
from lib.ledstrip import LEDStrip LEDStrip().fillOff()
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,420
jwolstenholme/pimp-my-ci
refs/heads/master
/monitors/circleci_monitor.py
from lib.const import * status_dict = { 'fixed' : SUCCESS, 'success' : SUCCESS, 'failed' : FAILURE, 'building_from_fixed' : BUILDING_FROM_SUCCESS, 'building_from_success' : BUILDING_FROM_SUCCESS, 'building_from_failed' : BUILDING_FROM_FAILURE, ...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,421
jwolstenholme/pimp-my-ci
refs/heads/master
/gui/main.py
from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.boxlayout import BoxLayout from kivy.graphics import Color, Rectangle from kivy.clock import Clock from kivy.clock import mainthread from pimp_my_ci import PimpMyCi import threading import time SIZE = 15 class CanvasApp(App): def on_stop(...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,422
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/config.py
class Config: total_number_leds = 32 polling_interval_secs = 3 platform = 'circleci' job_defaults = dict( num_leds = 32 ) # The build jobs to monitor - defaults are overridden jobs = [ dict( name = 'vix', url = 'https://circleci.com/api/v1/project/DiUS/vix?circle-token=8dd04ea68b5caf87a3b...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,423
jwolstenholme/pimp-my-ci
refs/heads/master
/pollers/http_json_poller.py
from time import sleep import logging import sys import threading import urllib2 import yaml from lib.config import Config log = logging.getLogger() class HttpJsonPoller(threading.Thread): def __init__(self, build_jobs, build_monitor): threading.Thread.__init__(self) self.daemon = True self.build_mon...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,424
jwolstenholme/pimp-my-ci
refs/heads/master
/pollers/travis_poller.py
import urllib2 from http_json_poller import HttpJsonPoller class TravisPoller(HttpJsonPoller): def create_request(self, job): return urllib2.Request(job.url, headers={"Accept" : "application/vnd.travis-ci.2+json"})
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,425
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/sounds_controller.py
from lib.const import * from sounds.player import Player class SoundsController: def __init__(self, job_names): self.sound_player = Player() self.play_sounds = dict.fromkeys(job_names, False) def update_build_status(self, job, status): if (not self.play_sounds[job.name]): self.play_sounds[job....
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,426
jwolstenholme/pimp-my-ci
refs/heads/master
/tests/lib/test_buildJob.py
from unittest import TestCase from lib.build_job import BuildJob class TestBuildJob(TestCase): def setUp(self): self.build_job = BuildJob(dict(name='Test Build Job', url='http://some/url')) def test_job_name_validation(self): self.assertRaises(ValueError, BuildJob, dict(name=None, url='http:/...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,427
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/build_job.py
import Queue from lib.config import Config # TODO rename all these to just 'job' class BuildJob: def __init__(self, dictionary): self.name = dictionary.get('name') self.url = dictionary.get('url') self.num_leds = dictionary.get('num_leds', 1) self.offset = dict...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,428
jwolstenholme/pimp-my-ci
refs/heads/master
/sounds/player.py
import os from random import randrange import glob import logging import subprocess import signal log = logging.getLogger() class Player: def play_random_start_sound(self): self.play_this_thing(self.randomly_choose_mp3_in_sub_directory("start_build")) def play_random_success_sound(self): sel...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,429
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/const.py
SUCCESS = 0 BUILDING_FROM_SUCCESS = 1 FAILURE = 2 BUILDING_FROM_FAILURE = 3 UNKNOWN = 4 BUILDING_FROM_UNKNOWN = 5 OFF = 6 GREEN = (0, 255, 0) RED = (255, 0, 0) YELLOW = (255, 255, 0) BLUE = (0, 0, 255) NONE = ...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,430
jwolstenholme/pimp-my-ci
refs/heads/master
/monitors/jenkins_monitor.py
from lib.const import * status_dict = { 'aborted_anime' : BUILDING_FROM_UNKNOWN, 'blue' : SUCCESS, 'blue_anime' : BUILDING_FROM_SUCCESS, 'disabled_anime' : BUILDING_FROM_UNKNOWN, 'grey_anime' : BUILDING_FROM_UNKNOWN, 'notbuilt_anime' : BUILDING_FROM_UNKNOWN, 'red' : F...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,431
jwolstenholme/pimp-my-ci
refs/heads/master
/pimp_my_ci.py
# script expects RPI_HOME to be set as an env var import sys import os import logging import threading import traceback import Queue from time import sleep from threading import Thread from lib.config import Config from lib.ledstrip import LEDStrip from lib.build_jobs import BuildJobs from lib.lights_controller impor...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,432
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/rgbcolour.py
class RGBColour: def __init__(self, r=0.0, g=0.0, b=0.0, bright=1.0): if(r > 255.0 or r < 0.0 or g > 255.0 or g < 0.0 or b > 255.0 or b < 0.0): raise ValueError('RGB values must be between 0 and 255') if(bright > 1.0 or bright < 0.0): raise ValueError('Brightness must be between 0.0 and 1.0') ...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,433
jwolstenholme/pimp-my-ci
refs/heads/master
/check_config.py
from lib.build_jobs import BuildJobs from lib.config import Config import urllib2 import json class Check: def __init__(self): self.build_jobs = BuildJobs.from_dictionaries(Config.platform, Config.job_defaults, Config.jobs) self.printGlobal() self.printJobs() self.printLedLayout() self.printTe...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,434
jwolstenholme/pimp-my-ci
refs/heads/master
/lib/build_jobs.py
import Queue from threading import Thread from time import sleep from lib.build_job import BuildJob from monitors.circleci_monitor import CircleciMonitor from monitors.jenkins_monitor import JenkinsMonitor from monitors.travis_monitor import TravisMonitor from pollers.http_json_poller import HttpJsonPoller from poller...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,435
jwolstenholme/pimp-my-ci
refs/heads/master
/monitors/travis_monitor.py
from lib.const import * status_dict = { 'passed' : SUCCESS, 'failed' : FAILURE } class TravisMonitor: def __init__(self, job_queues): self.job_queues = job_queues self.job_statuses = dict.fromkeys(self.job_queues.keys()) def process_build_for_job(self, build, job): raw_status = build['r...
{"/lib/lights_controller.py": ["/lib/const.py"], "/gui/main.py": ["/pimp_my_ci.py"], "/pollers/http_json_poller.py": ["/lib/config.py"], "/lib/sounds_controller.py": ["/lib/const.py", "/sounds/player.py"], "/tests/lib/test_buildJob.py": ["/lib/build_job.py"], "/lib/build_job.py": ["/lib/config.py"], "/monitors/jenkins_...
9,436
ijmazur/pwpflask
refs/heads/main
/flaskblog/users/utils.py
import os import secrets from PIL import Image from flask import url_for, current_app from flask_mail import Message from flaskblog import mail # random hex from secrets is a base for randomising name of picture, so it never hurts our db # we save the file with same extension as its uploaded (os - needed for that) # ...
{"/flaskblog/coins/routes.py": ["/flaskblog/models.py"], "/flaskblog/posts/routes.py": ["/flaskblog/models.py"], "/flaskblog/users/forms.py": ["/flaskblog/models.py"]}
9,437
ijmazur/pwpflask
refs/heads/main
/flaskblog/weather/routes.py
import configparser import os import requests from flask import render_template, Blueprint, request weather = Blueprint('weather', __name__) # OWM_API = os.environ.get('OWM_API') # asking what city we are looking for @weather.route("/weather") def weather_dashboard(): return render_template('weather.html') # f...
{"/flaskblog/coins/routes.py": ["/flaskblog/models.py"], "/flaskblog/posts/routes.py": ["/flaskblog/models.py"], "/flaskblog/users/forms.py": ["/flaskblog/models.py"]}
9,438
ijmazur/pwpflask
refs/heads/main
/flaskblog/coins/routes.py
from flask import render_template, request, Blueprint from flaskblog.models import Post import os import coinmarketcapapi import json from bs4 import BeautifulSoup import requests from types import SimpleNamespace # coins = Blueprint('coins', __name__) CMP_API = os.environ.get('CMP_API') # cmc = coinmarketcapapi.CoinM...
{"/flaskblog/coins/routes.py": ["/flaskblog/models.py"], "/flaskblog/posts/routes.py": ["/flaskblog/models.py"], "/flaskblog/users/forms.py": ["/flaskblog/models.py"]}
9,439
ijmazur/pwpflask
refs/heads/main
/flaskblog/posts/routes.py
from flask import render_template, url_for, flash, redirect, request, abort, Blueprint from flask_login import current_user, login_required from flaskblog import db from flaskblog.models import Post from flaskblog.posts.forms import PostForm posts = Blueprint('posts', __name__) # need to be logged in to create a pos...
{"/flaskblog/coins/routes.py": ["/flaskblog/models.py"], "/flaskblog/posts/routes.py": ["/flaskblog/models.py"], "/flaskblog/users/forms.py": ["/flaskblog/models.py"]}
9,440
ijmazur/pwpflask
refs/heads/main
/flaskblog/users/forms.py
from flask_wtf import FlaskForm from flask_wtf.file import FileField, FileAllowed from wtforms import StringField, PasswordField, SubmitField, BooleanField from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError from flask_login import current_user from flaskblog.models import User class R...
{"/flaskblog/coins/routes.py": ["/flaskblog/models.py"], "/flaskblog/posts/routes.py": ["/flaskblog/models.py"], "/flaskblog/users/forms.py": ["/flaskblog/models.py"]}
9,441
ijmazur/pwpflask
refs/heads/main
/flaskblog/models.py
from datetime import datetime from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from flask import current_app from flaskblog import db, login_manager from flask_login import UserMixin @login_manager.user_loader def load_user(user_id): return User.query.get(int(user_id)) # importing from db....
{"/flaskblog/coins/routes.py": ["/flaskblog/models.py"], "/flaskblog/posts/routes.py": ["/flaskblog/models.py"], "/flaskblog/users/forms.py": ["/flaskblog/models.py"]}
9,469
aymane081/python_algo
refs/heads/master
/arrays/increasing_triplet_subsequence.py
class Solution: def has_increasing_subsequence(self, nums): smallest, next_smallest = float('inf'), float('inf') for num in nums: # if num <= smallest: # smallest = num # elif num <= next_smallest: # next_smallest = num # else: ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,470
aymane081/python_algo
refs/heads/master
/arrays/dissapeared_numbers.py
class Solution(object): def dissapeared_numbers(self, numbers): if not numbers: return [] n = len(numbers) result = [i for i in range(1, n + 1)] for num in numbers: result[num - 1] = 0 self.delete_zeros(result) return result ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,471
aymane081/python_algo
refs/heads/master
/arrays/teemo_attacking.py
# 495 # time: O(n) # space: O(1) class Solution: def find_poisoned_duration(self, timeSeries, duration): result = 0 if not timeSeries: return result timeSeries.append(float('inf')) for i in range(1, len(timeSeries)): result += min(timeSeries...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,472
aymane081/python_algo
refs/heads/master
/linkedList/linked_list_cycle.py
from utils.listNode import ListNode class Solution: def has_cycle(self, head): if not head or not head.next: return False slow, fast = head.next, head.next.next while fast and fast.next: if fast == slow: return True slow = s...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,473
aymane081/python_algo
refs/heads/master
/dynamicProgramming/target_sum.py
from collections import defaultdict class Solution: def target_sum(self, nums, target): if not nums: return 0 sums = defaultdict(int) sums[0] = 1 running = nums[:] for i in range(len(running) - 2, -1, -1): running[i] += running[i + 1] ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,474
aymane081/python_algo
refs/heads/master
/graphs/surronded_regions.py
class Solution: def surrond(self, matrix): if not matrix or not matrix.rows_count or not matrix.cols_count: return matrix for row in range(matrix.rows_count): self.dfs(row, 0, matrix) self.dfs(row, matrix.cols_count - 1, matrix) for col i...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,475
aymane081/python_algo
refs/heads/master
/linkedList/reverse_linked_list.py
from utils.listNode import ListNode class Solution: def reverse(self, head): rev = None while head: rev, rev.next, head = head, rev, head.next return rev def reverse2(self, head): rev = None while head: next = head.next hea...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,476
aymane081/python_algo
refs/heads/master
/arrays/maximum_product_subarray.py
class Solution: def get_maximum_product(self, nums): max_so_far = float('-inf') max_here, min_here = 1, 1 for num in nums: max_here, min_here = max(max_here * num, min_here * num, num), min(min_here * num, max_here * num, num) max_so_far = max(max_so_far, max_here) ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,477
aymane081/python_algo
refs/heads/master
/arrays/summary_ranges.py
class Solution: def get_summary_ranges(self, nums): result = [] for i, num in enumerate(nums): if not result or nums[i] > nums[i - 1] + 1: result.append(str(num)) else: start = result[-1].split(' -> ')[0] result[-1] = ' -> '.joi...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,478
aymane081/python_algo
refs/heads/master
/strings/multiply_strings.py
class Solution(object): def multiply(self, num1, num2): """ :type num1: str :type num2: str :rtype: str """ result = [0] * (len(num1) + len(num2)) num1, num2 = num1[::-1], num2[::-1] for i in range(len(num1)): for j in range(len(num2)): ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,479
aymane081/python_algo
refs/heads/master
/dynamicProgramming/house_robber2.py
# 213 class Solution: def rob(self, houses): if not houses: return 0 # last house is not robbed rob_first = self.helper(houses, 0, len(houses) - 2) # first house is not robbed skip_first = self.helper(houses, 1, len(houses) - 1) return max(r...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,480
aymane081/python_algo
refs/heads/master
/strings/compare_versions.py
import unittest class Solution(object): def compare_versions(self, version1, version2): """ :type version1: str :type version2: str :rtype: int """ if not version1 or not version2: return None digits1 = list(map(int, version1.split('.'))) ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,481
aymane081/python_algo
refs/heads/master
/arrays/max_consecutive_ones.py
class Solution(object): def max_consecutive_ones(self, numbers): if not numbers: return 0 longest, count = 0, 0 for num in numbers: if num > 0: count += 1 longest = max(longest, count) else: count = 0 ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,482
aymane081/python_algo
refs/heads/master
/dynamicProgramming/range_sum_query2.py
from utils.matrix import Matrix class RangeSumQuery: def __init__(self, matrix): """ :type matrix: Matrix :rtype: None """ matrix_sum = [[0 for _ in range(matrix.col_count + 1)] for _ in range(matrix.row_count + 1)] for row in range(1, matrix.row_count + 1): ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,483
aymane081/python_algo
refs/heads/master
/linkedList/remove_duplicates.py
#83 from utils.listNode import ListNode class Solution: def remove_duplicates(self, head): if not head: return curr = head while curr and curr.next: if curr.value == curr.next.value: curr.next = curr.next.next else: ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,484
aymane081/python_algo
refs/heads/master
/binarySearch/min_circular_sorted_array.py
class Solution: def get_min(self, nums): if not nums: return None left, right = 0, len(nums) - 1 while left < right: if nums[left] <= nums[right]: # not rotated break mid = (left + right) // 2 if nums[mid] < nums[left]: # min m...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,485
aymane081/python_algo
refs/heads/master
/linkedList/delete_nth_node_from_end.py
#19 from utils.listNode import ListNode class Solution: def delete_from_end(self, head, n): if not head: return front, back = head, head dummy = prev = ListNode(None) while n > 0: back = back.next n -= 1 while back: ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,486
aymane081/python_algo
refs/heads/master
/linkedList/odd_even_linked_list.py
# 328 from utils.listNode import ListNode class Solution: def odd_even_list(self, head): if not head: return None odd = head even_head, even = head.next, head.next while even and even.next: odd.next = even.next odd = odd.next ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,487
aymane081/python_algo
refs/heads/master
/arrays/remove_duplicate_sorted_array.py
class Solution(object): def remove_duplicate(self, arr): """ type arr: list rtype: int """ if not arr: return 0 j = 0 for i in range(1, len(arr)): if arr[i] != arr[j]: j += 1 arr[j] = arr[i] j +=...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,488
aymane081/python_algo
refs/heads/master
/arrays/find_all_duplicates.py
#442 class Solution: def get_duplicates(self, nums): if not nums: return None result = [] for num in nums: index = abs(num) - 1 if nums[index] < 0: result.append(abs(num)) else: nums[index] *= -1 return ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,489
aymane081/python_algo
refs/heads/master
/graphs/reconstruct_itenirary.py
from collections import defaultdict import unittest class Solution: def reconstruct_itinerary(self, flights): graph = self.build_graph(flights) path = [] self.dfs('JFK', graph, path, len(flights)) return path def dfs(self, node, graph, path, remaining): if node == 'X'...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,490
aymane081/python_algo
refs/heads/master
/trees/binary_tree_pruning.py
#814 from utils.treeNode import TreeNode class Solution: def prune(self, root): if not root: return root root.left, root.right = self.prune(root.left), self.prune(root.right) return root if root.value == 1 or root.left or root.right else None
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,491
aymane081/python_algo
refs/heads/master
/linkedList/linked_list_components.py
# 817 from utils.listNode import ListNode class Solution: # time: O(len of linked list) # space: O(len of G) def get_connected_count(self, head, G): count = 0 if not head: return count values_set = set(G) prev = ListNode(None) prev.next = head...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,492
aymane081/python_algo
refs/heads/master
/trees/path_sum.py
from utils.treeNode import TreeNode class Solution: def has_path_sum(self, node, sum): if not node: return False sum -= node.value if not sum and not node.left and not node.right: return True return self.has_path_sum(node.left, sum) or self...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,493
aymane081/python_algo
refs/heads/master
/arrays/matrix_spiral2.py
class Solution: def generate_spiral(self, n): if n <= 0: raise Exception('n should be bigger than 0') # matrix = [[0] * n] * n # for some reason this does not work matrix = [[0 for _ in range(n)] for _ in range(n)] row, col = 0, 0 d_row, d_col = 0, 1 for ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,494
aymane081/python_algo
refs/heads/master
/strings/time_conversion.py
import unittest class Solution(object): def time_conversion(self, time_str): if not time_str: return None time_list = list(time_str) is_pm = time_list[-2].lower() == 'p' # handle the 12 AM case. It should be converted to 00 if not is_pm and time_str[:2...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,495
aymane081/python_algo
refs/heads/master
/strings/ransom_note.py
import collections import unittest # time: O(M + N) - space: O(N) # def can_construct(ransom, magazine): # if not magazine: # return False # ransom_dict = dict() # for s in ransom: # if s not in ransom_dict: # ransom_dict[s] = 1 # else: # ransom_dict[s] +=...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,496
aymane081/python_algo
refs/heads/master
/binarySearch/find_right_interval.py
from utils.interval import Interval class Solution: def get_right_intervals(self, intervals): intervals = [(intervals[i], i) for i in range(len(intervals))] # In order to do binary search, the array needs to be sorted # We need to sort by the start because the intervals with a bigger start ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,497
aymane081/python_algo
refs/heads/master
/trees/maximum_binary_tree.py
#654 from utils.treeNode import TreeNode class Solution: def build_maximum_tree(self, nums): if not nums: return None return self.helper(nums, 0, len(nums) - 1) def helper(self, nums, start, end): if start > end: return None max_nu...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,498
aymane081/python_algo
refs/heads/master
/utils/listNode.py
class ListNode: def __init__(self, value): self.value = value self.next = None # def __repr__(self): # return '(value = {}, next: {})'.format(self.value, self.next) def __repr__(self): nodes = [] while self: nodes.append(str(self.value)) ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,499
aymane081/python_algo
refs/heads/master
/trees/diameter_binary_tree.py
# 543 from utils.treeNode import TreeNode # time: O(N) # space: O(N) class Solution: def dimater(self, root): self.result = 0 if not root: return self.result def depth(root): left_depth = 1 + depth(root.left) if root.left else 0 right_depth = 1 ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,500
aymane081/python_algo
refs/heads/master
/arrays/number_of_subarrays_bounded_maximum.py
# 795 class Solution: def subarray_count(self, nums, L, R): # dp is the number of subarrays ending with nums[i] result, dp = 0, 0 prev_invalid_index = -1 if not nums: return result for i, num in enumerate(nums): if num < L: r...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,501
aymane081/python_algo
refs/heads/master
/trees/delete_note_bst.py
class Solution: # time: O(N) worst case, O(height) average # space: O(N) worst case, O(height) average def delete_node(self, root, value): if not root: return None if root.value > value: root.left = self.delete_node(root.left, value) elif root.value <...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,502
aymane081/python_algo
refs/heads/master
/linkedList/reorder_list.py
#143 from utils.listNode import ListNode class Solution: def reorder(self, head): if not head: return head fast, slow = head, head while fast and fast.next: fast = fast.next.next slow = slow.next rev, node = None, slow ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,503
aymane081/python_algo
refs/heads/master
/trees/binary_tree_from_sorted_array.py
from utils.treeNode import TreeNode class Solution: # time: O(N) - space: O(N) def build_binary_tree(self, nums): if not nums: return None return self.convert(nums, 0, len(nums) - 1) def convert(self, nums, left, right): if left > right: return None...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,504
aymane081/python_algo
refs/heads/master
/utils/matrix.py
class Matrix: def __init__(self, rows): self.rows = rows self.row_count = len(rows) self.col_count = len(rows[0]) def is_valid_cell(self, row, col): return ( row >= 0 and row < self.row_count and col >= 0 and col < self.col_count ) de...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,505
aymane081/python_algo
refs/heads/master
/arrays/target_sum_amazon.py
class Solution: def sum_target(self, collection1, collection2, target): result = [] sum_dict = dict() for nums in [collection1, collection2]: for num in nums: remaining = target - num if remaining in sum_dict: result.append((r...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,506
aymane081/python_algo
refs/heads/master
/trees/invert_binary_tree.py
from utils.treeNode import TreeNode class Solution: def invert(self, node): if not node: return self.invert(node.left) self.invert(node.right) node.left, node.right = node.right, node.left node1 = TreeNode(1) node2 = TreeNode(2) node3 = TreeNode(3) node4 = Tr...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,507
aymane081/python_algo
refs/heads/master
/strings/simplify_path.py
class Solution(object): def simplify_path(self, path): """ :type path: str :rtype: str """ directories = path.split('/') # get the directories from the path result = [] # stack to hold the result for dir in directories: if dir == '..' and result...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,508
aymane081/python_algo
refs/heads/master
/arrays/insert_delete_get_random.py
import random class RandomizedSet: def __init(self): self.mapping = {} self.items = [] def insert(self, value): if value not in self.mapping: self.items.append(value) self.mapping[value] = len(self.items) - 1 return True return False ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,509
aymane081/python_algo
refs/heads/master
/trees/print_binary_tree.py
# 655 #time: O(H * 2**H - 1) need to fill the result array # space: O(H * 2**H - 1) the number of elements in the result array from utils.treeNode import TreeNode class Solution: def print(self, root): if not root: return [] height = self.get_height(root) result = [[...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,510
aymane081/python_algo
refs/heads/master
/arrays/majority_element.py
class Solution(object): # this algorithm is called the Boyer-Moore majority voting algorithm # https://stackoverflow.com/questions/4325200/find-the-majority-element-in-array # the majority element appears more than all the other elements combined. Therefore, if we keep a # counter and change the major...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,511
aymane081/python_algo
refs/heads/master
/arrays/flipping_image.py
# 832 class Solution: def flip(self, matrix): for row in matrix: for i in range((len(row) + 1) // 2): row[i], row[-1 -i] = 1 - row[-1 -i], 1 - row[i] return matrix solution = Solution() matrix = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]] print(solution.flip(mat...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,512
aymane081/python_algo
refs/heads/master
/linkedList/delete_node_linked_list.py
from utils.listNode import ListNode #237 class Solution: def delete_node(self, node): # node is not the tail => node.next exists node.value = node.next.value node.next = node.next.next
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,513
aymane081/python_algo
refs/heads/master
/dynamicProgramming/maximum_square.py
from utils.matrix import Matrix class Solution: # O(m * n * min(m, n)) time and O(1) space def get_max_square(self, matrix): """ :type matrix: Matrix :rtype: int """ max_area = 0 for row in range(1, matrix.row_count): for col in range(1, matrix.col_co...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,514
aymane081/python_algo
refs/heads/master
/trees/binary_tree_paths.py
from utils.treeNode import TreeNode class Solution: def get_paths(self, node): result = [] if not node: return result self.helper([], node, result) return [" -> ".join(path) for path in result] def helper(self, prefix, node, result): if not node...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,515
aymane081/python_algo
refs/heads/master
/dynamicProgramming/triangle.py
class Solution: def get_min_path(self, triangle): """ type triangle: List[List[int]] rtype: int """ if not triangle: return 0 for row in range(len(triangle) - 2, -1, -1): for col in range(row + 1): triangle[row][col] += min(tr...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,516
aymane081/python_algo
refs/heads/master
/strings/substring_without_repeating_characters.py
# Time: O(N) - Space: O(1): the length of the set/map is bounded by the number of the alphabet # set.clear() is O(1) class Solution(object): def longest_unique_substring(self, str): if not str: return 0 str_set = set() result = 0 for char in str: if...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,517
aymane081/python_algo
refs/heads/master
/arrays/word_search.py
from utils.matrix import Matrix class Solution: def exist(self, matrix, word): """ :type matrix: Matrix :type word: Str :rtype: boolean """ if not matrix.row_count or not matrix.col_count: return False for row in range(matrix.row_count): ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,518
aymane081/python_algo
refs/heads/master
/dynamicProgramming/longest_increasing_sequence.py
from bisect import bisect class Solution: # Time: O(n log n) - Space: O(n) def get_longest_increasing_sequence(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 dp = [] for num in nums: index = b...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,519
aymane081/python_algo
refs/heads/master
/arrays/remove_duplicate_sorted_array2.py
class Solution: def remove_duplicates(self, nums): if len(nums) <= 2: return len(nums) j = 1 for i in range(2, len(nums)): if nums[i] > nums[j - 1]: j += 1 nums[j] = nums[i] j += 1 for _ in range(j, len...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,520
aymane081/python_algo
refs/heads/master
/graphs/topological_sort.py
class Solution: def topological_sort(self, graph): result = [] discovered = set() path = [] for node in graph: self.helper(node, result, discovered, path) return result.reverse() def helper(self, node, result, discovered, path): if node ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,521
aymane081/python_algo
refs/heads/master
/binarySearch/intersection_of_two_arrays.py
class Solution: def get_interesection(self, nums1, nums2): set1 = set(nums1) intersection = set() for num in nums2: if num in set1: intersection.add(num) return list(intersection)
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,522
aymane081/python_algo
refs/heads/master
/arrays/container_with_most_water.py
class Solution(object): def max_area(self, heights): """ :type heights: List(int) :rtype: int """ if not heights: return 0 left = 0 right = len(heights) - 1 # calculate the area of the outer container max_area = (right - left) * mi...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,523
aymane081/python_algo
refs/heads/master
/arrays/random_pick_index.py
import random from collections import defaultdict class Solution: # O(1) space and time in initialization. O(n) time and O(1) space when getting the rand index def __init__(self, nums): self.nums = nums def get_random_index(self, target): result, count = None, 0 for i, num in enum...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,524
aymane081/python_algo
refs/heads/master
/strings/longestCommonPrefix.py
class Solution: def get_longest_common_prefix(self, words): if not words: return '' min_word_length = min(words, key=len) start, end = 0, len(min_word_length) - 1 while start <= end: mid = (start + end) // 2 if not self.is_common_prefix(...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,525
aymane081/python_algo
refs/heads/master
/utils/interval.py
class Interval: def __init__(self, start, end): self.start = start self.end = end def __repr__(self): return "[{0}, {1}]".format(self.start, self.end)
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,526
aymane081/python_algo
refs/heads/master
/dynamicProgramming/word_break.py
class Solution: def word_break(self, s, wordDict): if not wordDict: return False if not s: return True can_make = [True] + [False for _ in range(len(s))] for i in range(1, len(s) + 1): for j in range(i - 1, -1, -1): ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,527
aymane081/python_algo
refs/heads/master
/linkedList/merge_two_sorted_lists.py
from utils.listNode import ListNode class Solution: def merge(self, l1, l2): if not l1 or not l2: return l1 or l2 node1, node2 = l1, l2 head = None curr = None while node1 and node2: min_value = min(node1.value, node2.value) if ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,528
aymane081/python_algo
refs/heads/master
/graphs/clone_graph.py
class Node: def __init__(self, label): self.label = label self.neighbors = [] class Solution: def clone_graph(self, node): if not node: return None cloned_start = Node(node.key) node_mapping = { node: cloned_start} queue = [node] whi...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,529
aymane081/python_algo
refs/heads/master
/arrays/search_matrix.py
from utils.matrix import Matrix import unittest class Solution: def search(self, matrix, value): if value < matrix[0][0] or value > matrix[-1][-1]: return False row = self.get_row(matrix, value) return self.binary_search_row(matrix[row], value) def get_row(self, ma...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,530
aymane081/python_algo
refs/heads/master
/arrays/subarray_sum_equals_k.py
# 560 from collections import defaultdict # time: O(N) # space: O(N) class Solution: def subarray_sum(self, nums, k): result = 0 if not nums: return result sum_map = defaultdict(int) sum_map[0] = 1 curr_sum = 0 for num in nums: cur...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,531
aymane081/python_algo
refs/heads/master
/graphs/evaluate_division.py
from collections import defaultdict class Solution: def solve_queries(self, equations, values, queries): graph = self.build_graph(equations, values) result = [] for query in queries: result.append(self.dfs(query[0], query[1], 1, graph, set())) return result ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,532
aymane081/python_algo
refs/heads/master
/arrays/contains_duplicates.py
class Solution(object): def contains_duplicates(self, numbers): number_set = set(numbers) return len(numbers) != len(number_set) def contains_duplicates2(self, numbers): """ :type numbers: list :rtype : Boolean """ numbers.sort() for i in range(1...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,533
aymane081/python_algo
refs/heads/master
/binarySearch/sqrt.py
class Solution: def sqrt(self, n): if n == 0: return 0 left, right = 1, n # while True: # mid = (left + right) // 2 # if mid * mid > n: # right = mid - 1 # else: # if (mid + 1) * (mid + 1) > n: #...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,534
aymane081/python_algo
refs/heads/master
/graphs/course_schedule.py
from collections import defaultdict class Solution: def course_schedule(self, classes): if not classes: return[] graph = self.build_graph(classes) result = [] path = [] discovered = set() for node in graph: self.topological_sort(nod...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,535
aymane081/python_algo
refs/heads/master
/arrays/reshape_matrix.py
# 566 # time: O(N * M) # space: O(N * M) class Solution: def reshape(self, nums, r, c): if not nums or len(nums) * len(nums[0]) != r * c: return nums rows, cols = len(nums), len(nums[0]) queue = [] for row in range(rows): for col in range(cols): ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,536
aymane081/python_algo
refs/heads/master
/trees/maximum_width_binary_tree.py
#662 from utils.treeNode import TreeNode class Solution2: def max_width(self, root): queue = [(root, 0, 0)] curr_level, left, result = 0, 0, 0 for node, pos, level in queue: if node: queue.append((node.left, 2 * pos, level + 1)) queue.append((no...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,537
aymane081/python_algo
refs/heads/master
/strings/reverse_words_in_string.py
class Solution(object): def reverse_words(self, string): if not string: return '' # words = string.split() # return ' '.join(words[::-1]) word_lists = [[]] for i, c in enumerate(string): if c != ' ': word_lists[-1].append(c) ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,538
aymane081/python_algo
refs/heads/master
/strings/anagram_groups.py
from collections import defaultdict # Gotcha 1: there is no sort for strings. # You have to convert the word to a list, then sort it using list.sort(), # then reconstruct the string using ''.join(sorted_list) # Gotcha 2: defaultdict is part of the collections library class Solution(object): # Time: O(n * k * log...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...
9,539
aymane081/python_algo
refs/heads/master
/linkedList/intersection_of_two_linked_list.py
from utils.listNode import ListNode class Solution: def get_intersection(self, head1, head2): if not head1 or not head2: return None l1, l2 = self.get_length(head1), self.get_length(head2) node1, node2 = self.move_ahead(head1, l1 - l2), self.move_ahead(head2, l2 - l1) ...
{"/linkedList/linked_list_cycle.py": ["/utils/listNode.py"], "/linkedList/reverse_linked_list.py": ["/utils/listNode.py"], "/dynamicProgramming/range_sum_query2.py": ["/utils/matrix.py"], "/linkedList/remove_duplicates.py": ["/utils/listNode.py"], "/linkedList/delete_nth_node_from_end.py": ["/utils/listNode.py"], "/lin...