text stringlengths 0 1.05M | meta dict |
|---|---|
# 212. Word Search II
#
# Given a 2D board and a list of words from the dictionary, find all words in the board.
#
# Each word must be constructed from letters of sequentially adjacent cell,
# where "adjacent" cells are those horizontally or vertically neighboring.
# The same letter cell may not be used more than once ... | {
"repo_name": "gengwg/leetcode",
"path": "212_word_search_ii.py",
"copies": "1",
"size": "3601",
"license": "apache-2.0",
"hash": -9122605751815904000,
"line_mean": 27.5793650794,
"line_max": 108,
"alpha_frac": 0.5220772008,
"autogenerated": false,
"ratio": 3.533856722276742,
"config_test": fal... |
# 2/13/14
# Charles O. Goddard
import pylab
import numpy
from matplotlib import cm
from matplotlib import pyplot
from matplotlib.colors import rgb2hex
from matplotlib.patches import Polygon
from matplotlib.collections import LineCollection
from mpl_toolkits.basemap import Basemap as Basemap
import apidata
m = Basema... | {
"repo_name": "thomasnat1/DataScience2014CDC",
"path": "pulls_per_state_percapita.py",
"copies": "1",
"size": "3409",
"license": "mit",
"hash": 6159638940638318000,
"line_mean": 35.6559139785,
"line_max": 74,
"alpha_frac": 0.7066588442,
"autogenerated": false,
"ratio": 2.4667149059334297,
"conf... |
# 215. Kth Largest Element in an Array
#
# Find the kth largest element in an unsorted array.
# Note that it is the kth largest element in the sorted order, not the kth distinct element.
#
# For example,
# Given [3,2,1,5,6,4] and k = 2, return 5.
#
# Note:
# You may assume k is always valid, 1 =< k <= array's length.
#... | {
"repo_name": "gengwg/leetcode",
"path": "215_kth_largest_element_in_an_array.py",
"copies": "1",
"size": "2908",
"license": "apache-2.0",
"hash": 8564448273041790000,
"line_mean": 30.6086956522,
"line_max": 92,
"alpha_frac": 0.5649931224,
"autogenerated": false,
"ratio": 3.3932322053675614,
"c... |
# 216. Combination Sum III
#
# Find all possible combinations of k numbers that add up to a number n,
# given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
#
#
# Example 1:
#
# Input: k = 3, n = 7
#
# Output:
#
# [[1,2,4]]
#
# Example 2:
#
# Input: k = 3, n = 9
#
# Ou... | {
"repo_name": "gengwg/leetcode",
"path": "216_combination_sum_iii.py",
"copies": "1",
"size": "1101",
"license": "apache-2.0",
"hash": -9199431798715370000,
"line_mean": 24.0227272727,
"line_max": 105,
"alpha_frac": 0.5821980018,
"autogenerated": false,
"ratio": 3.1820809248554913,
"config_test... |
# 217. Contains Duplicate
#
# Given an array of integers, find if the array contains any duplicates.
# Your function should return true if any value appears at least twice in the array,
# and it should return false if every element is distinct.
class Solution(object):
# use hash map to mark if num already appeare... | {
"repo_name": "gengwg/leetcode",
"path": "217_contains_duplicate.py",
"copies": "1",
"size": "1267",
"license": "apache-2.0",
"hash": -2830687561886935600,
"line_mean": 25.9574468085,
"line_max": 84,
"alpha_frac": 0.543804262,
"autogenerated": false,
"ratio": 4.195364238410596,
"config_test": f... |
# 2/18/17 (better)
class Solution(object):
def findMaxLength(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
res, tot, first_idx = 0, 0, {0: -1}
for i in range(len(nums)):
tot += 1 if nums[i] else -1
if tot in first_idx:
... | {
"repo_name": "cc13ny/algo",
"path": "leetcode/525-Contiguous-Array/one_pass.py",
"copies": "4",
"size": "1231",
"license": "mit",
"hash": 1671432206566151200,
"line_mean": 25.7826086957,
"line_max": 72,
"alpha_frac": 0.4354183591,
"autogenerated": false,
"ratio": 3.3091397849462365,
"config_te... |
# 218. The Skyline Problem
# A city's skyline is the outer contour of the silhouette formed by all the buildings
# in that city when viewed from a distance.
# Now suppose you are given the locations and height of all the buildings
# as shown on a cityscape photo (Figure A),
# write a program to output the skyline form... | {
"repo_name": "gengwg/leetcode",
"path": "218_skyline_problem.py",
"copies": "1",
"size": "3401",
"license": "apache-2.0",
"hash": -726914847247832600,
"line_mean": 43.0909090909,
"line_max": 102,
"alpha_frac": 0.627982327,
"autogenerated": false,
"ratio": 3.2738669238187077,
"config_test": fal... |
# 219. Contains Duplicate II
#
# Given an array of integers and an integer k,
# find out whether there are two distinct indices i and j in the array
# such that nums[i] = nums[j] and the absolute difference between i and j is at most k.
class Solution(object):
def containsNearbyDuplicate(self, nums, k):
... | {
"repo_name": "gengwg/leetcode",
"path": "219_contains_duplicate_ii.py",
"copies": "1",
"size": "1674",
"license": "apache-2.0",
"hash": 3758234018225934000,
"line_mean": 30.5849056604,
"line_max": 93,
"alpha_frac": 0.4970131422,
"autogenerated": false,
"ratio": 4.164179104477612,
"config_test"... |
# 21. Merge Two Sorted Lists - LeetCode
# https://leetcode.com/problems/merge-two-sorted-lists/description/
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
a = ListNode(0)
p = a
for i in [1,3,4,5,7,10]:
p.next = ListNode... | {
"repo_name": "heyf/cloaked-octo-adventure",
"path": "leetcode/021_merge-two-sorted-lists.py",
"copies": "1",
"size": "1230",
"license": "mit",
"hash": -7099723993260826000,
"line_mean": 20.9821428571,
"line_max": 67,
"alpha_frac": 0.5300813008,
"autogenerated": false,
"ratio": 3.106060606060606,... |
__author__ = 'Libao Jin'
__date__ = 'December 15, 2015'
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution(object):
def mergeTwoLists(self, l1, l2):
"""
:type l1: ListNode
:type l2: ListNod... | {
"repo_name": "imthomasking/LeetCode-Solutions",
"path": "solutions/021_MergeTwoSortedLists.py",
"copies": "2",
"size": "1997",
"license": "mit",
"hash": -7671783036222810000,
"line_mean": 22.7738095238,
"line_max": 52,
"alpha_frac": 0.4917376064,
"autogenerated": false,
"ratio": 3.38474576271186... |
# 21. Merge Two Sorted Lists
#
# Merge two sorted linked lists and return it as a new list.
# The new list should be made by splicing together the nodes of the first two lists.
#
# https://github.com/gengwg
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
se... | {
"repo_name": "gengwg/leetcode",
"path": "021_merge_two_sorted_lists.py",
"copies": "1",
"size": "1478",
"license": "apache-2.0",
"hash": 7258764197087888000,
"line_mean": 27.4230769231,
"line_max": 84,
"alpha_frac": 0.550744249,
"autogenerated": false,
"ratio": 3.622549019607843,
"config_test"... |
''' 21-plot_Sky-coverage.py
===============================================
AIM: Plots the Stray Light coverage difference between two 21-plot-Sky-coverage.py in terms of period of observation and accumulated observation time.
INPUT: files: - <orbit_id>_misc/ : files from 21-plot-Sky-coverage.py
variables: see secti... | {
"repo_name": "kuntzer/SALSA-public",
"path": "21b_plot_delta_Sky_corverage.py",
"copies": "1",
"size": "3917",
"license": "bsd-3-clause",
"hash": 7518852237313606000,
"line_mean": 27.8014705882,
"line_max": 150,
"alpha_frac": 0.6594332397,
"autogenerated": false,
"ratio": 2.7565095003518647,
"... |
''' 21-plot_Sky-coverage.py
===============================================
AIM: Plots the Stray Light coverage in % in terms of period of observation and accumulated observation time.
INPUT: files: - <orbit_id>_misc/ : files from 17-<...>.py
variables: see section PARAMETERS (below)
OUTPUT: in <orbit_id>_<SL_angle... | {
"repo_name": "kuntzer/SALSA-public",
"path": "21a_plot_Sky_corverage.py",
"copies": "1",
"size": "10180",
"license": "bsd-3-clause",
"hash": -3419558329013920300,
"line_mean": 28.4219653179,
"line_max": 171,
"alpha_frac": 0.6353634578,
"autogenerated": false,
"ratio": 2.7146666666666666,
"conf... |
# 21 septembre 2017
# astro_v2.py
from pylab import *
import os
def B3V_eq(x):
"""
:param x: abcsisse du point de la ligne B3V dont on veut obtenir l'ordonnee
:return: ordonnee du point de la ligne B3V correspondant a l'abscisse x (dans un graphique u-g vs g-r)
"""
return 0.9909 * x - 0.8901
d... | {
"repo_name": "anthonygi13/Recherche_etoiles_chaudes",
"path": "astro_v2.py",
"copies": "1",
"size": "18168",
"license": "apache-2.0",
"hash": 5559698047031839000,
"line_mean": 39.2638580931,
"line_max": 429,
"alpha_frac": 0.5966187565,
"autogenerated": false,
"ratio": 2.877812995245642,
"confi... |
# 222. Count Complete Tree Nodes
#
# Given a complete binary tree, count the number of nodes.
#
# Definition of a complete binary tree from Wikipedia:
# In a complete binary tree every level, except possibly the last, is completely filled,
# and all nodes in the last level are as far left as possible.
# It can have bet... | {
"repo_name": "gengwg/leetcode",
"path": "222_count_complete_tree_nodes.py",
"copies": "1",
"size": "1236",
"license": "apache-2.0",
"hash": -7309834225454632000,
"line_mean": 28.4285714286,
"line_max": 88,
"alpha_frac": 0.5995145631,
"autogenerated": false,
"ratio": 3.8990536277602525,
"config... |
# 2.2.4 http.client : https://docs.python.org/3.5/library/http.client.html
from http import client
from urllib.parse import urlencode
def get():
print("get method")
conn = client.HTTPConnection("www.example.com")
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print(r1.status, r1.reason... | {
"repo_name": "gnidoc327/django_web_dev_chater_2",
"path": "src/client/httplib_ex/httplib35.py",
"copies": "1",
"size": "1520",
"license": "mit",
"hash": 9042315069743869000,
"line_mean": 21.1764705882,
"line_max": 74,
"alpha_frac": 0.6021220159,
"autogenerated": false,
"ratio": 3.358574610244988... |
# 225. Implement Stack using Queues - LeetCode
# https://leetcode.com/problems/implement-stack-using-queues/description/
class MyStack(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.lst = list()
self.top_ptr = -1
def push(self, x):
... | {
"repo_name": "heyf/cloaked-octo-adventure",
"path": "leetcode/225_implement-stack-using-queues.py",
"copies": "1",
"size": "1762",
"license": "mit",
"hash": 4488783732710804500,
"line_mean": 23.1506849315,
"line_max": 73,
"alpha_frac": 0.4608399546,
"autogenerated": false,
"ratio": 3.58130081300... |
# 229. Majority Element II
#
# Given an integer array of size n,
# find all elements that appear more than n/3 times.
# The algorithm should run in linear time and in O(1) space.
#
class Solution(object):
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
... | {
"repo_name": "gengwg/leetcode",
"path": "229_majority_element_ii.py",
"copies": "1",
"size": "1979",
"license": "apache-2.0",
"hash": 7174184351880481000,
"line_mean": 24.4393939394,
"line_max": 126,
"alpha_frac": 0.5175699821,
"autogenerated": false,
"ratio": 2.4298118668596236,
"config_test"... |
# 2-2 Implement an algorithm to find the kth to last element of a
# a singly linked list
# Pseudo:
# Iterate through all to find the length
# Iterate again to get the kth last
class Node:
'''A node in a singly linked list'''
def __init__(self, data):
self.data = data
self.next = None
def... | {
"repo_name": "dmart914/CTCI",
"path": "02-linked-lists/2-2-kth-last.py",
"copies": "1",
"size": "2647",
"license": "apache-2.0",
"hash": -3433641861091806000,
"line_mean": 23.0636363636,
"line_max": 66,
"alpha_frac": 0.5746127692,
"autogenerated": false,
"ratio": 3.814121037463977,
"config_tes... |
# 23/05/2017
# BFS implementation with Manhattan distance heuristic
from queue import Queue
class Node(object):
def __init__(self, value, parent):
self.value = value
self.parent = parent
def knight_move(x, y):
possible_moves = [(-1, -2), (1, -2), (-1, 2), (1, 2),
(-2, -1... | {
"repo_name": "tlgs/dailyprogrammer",
"path": "Python/easy/e316.py",
"copies": "2",
"size": "1343",
"license": "unlicense",
"hash": 5111320444954970000,
"line_mean": 26.9791666667,
"line_max": 64,
"alpha_frac": 0.487714073,
"autogenerated": false,
"ratio": 3.4973958333333335,
"config_test": fal... |
# 230. Kth Smallest Element in a BST
#
# Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.
#
# Note:
# You may assume k is always valid, 1 ≤ k ≤ BST's total elements.
#
# Follow up:
# What if the BST is modified (insert/delete operations) often and you need to find the kt... | {
"repo_name": "gengwg/leetcode",
"path": "230_kth_smallest_element_bst.py",
"copies": "1",
"size": "2437",
"license": "apache-2.0",
"hash": 6398647803666822000,
"line_mean": 25.7362637363,
"line_max": 112,
"alpha_frac": 0.5277435265,
"autogenerated": false,
"ratio": 3.73159509202454,
"config_te... |
# 231. Power of Two
# Given an integer, write a function to determine if it is a power of two.
# http://www.cnblogs.com/grandyang/p/4623394.html
class Solution(object):
def isPowerOfTwo(self, n):
"""
:type n: int
:rtype: bool
"""
cnt = 0
while n > 0:
cnt ... | {
"repo_name": "gengwg/leetcode",
"path": "231_power_of_two.py",
"copies": "1",
"size": "1382",
"license": "apache-2.0",
"hash": -5602216100257937000,
"line_mean": 30.5238095238,
"line_max": 95,
"alpha_frac": 0.5377643505,
"autogenerated": false,
"ratio": 3.1226415094339623,
"config_test": false... |
# 232. Implement Queue using Stacks - LeetCode
# https://leetcode.com/problems/implement-queue-using-stacks/description/
class MyStack(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.lst = list()
self.top_ptr = -1
def push(self, x):
... | {
"repo_name": "heyf/cloaked-octo-adventure",
"path": "leetcode/232_implement-queue-using-stacks.py",
"copies": "1",
"size": "4269",
"license": "mit",
"hash": 7400754366323708000,
"line_mean": 23.2613636364,
"line_max": 76,
"alpha_frac": 0.4734129773,
"autogenerated": false,
"ratio": 3.84941388638... |
# 234. Palindrome Linked List - LeetCode
# https://leetcode.com/problems/palindrome-linked-list/description/
from helper.linked_list import LinkedList, traversal
class Solution(object):
def isPalindrome(self, head):
"""
:type head: ListNode
:rtype: bool
"""
def flip(head):
... | {
"repo_name": "heyf/cloaked-octo-adventure",
"path": "leetcode/234_palindrome-linked-list.py",
"copies": "1",
"size": "1611",
"license": "mit",
"hash": -8592622712887277000,
"line_mean": 24.1875,
"line_max": 67,
"alpha_frac": 0.4680322781,
"autogenerated": false,
"ratio": 3.464516129032258,
"co... |
# 234. Palindrome Linked List
#
# Given a singly linked list, determine if it is a palindrome.
#
# Follow up:
# Could you do it in O(n) time and O(1) space?
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
# http://blog.c... | {
"repo_name": "gengwg/leetcode",
"path": "234_palindrome_linked_list.py",
"copies": "1",
"size": "2359",
"license": "apache-2.0",
"hash": -310475316620664060,
"line_mean": 23.0714285714,
"line_max": 62,
"alpha_frac": 0.5150487495,
"autogenerated": false,
"ratio": 3.9382303839732886,
"config_tes... |
# 234. Palindrome Linked List
#
# Given a singly linked list, determine if its items form a palindrome.
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
def is_palindrome_rec(head):
def build_stack(node, revrsd, length):
... | {
"repo_name": "afbarnard/glowing-broccoli",
"path": "lc/000234.py",
"copies": "1",
"size": "1459",
"license": "mit",
"hash": 8963296934136820000,
"line_mean": 25.5272727273,
"line_max": 71,
"alpha_frac": 0.5867032214,
"autogenerated": false,
"ratio": 3.377314814814815,
"config_test": false,
"... |
# 237. Delete Node in a Linked List
#
# Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
#
# Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3,
# the linked list should become 1 -> 2 -> 4 after calling your function.
#
... | {
"repo_name": "gengwg/leetcode",
"path": "237_delete_node_in_linked_list.py",
"copies": "1",
"size": "1106",
"license": "apache-2.0",
"hash": -89155202194167120,
"line_mean": 34.6774193548,
"line_max": 110,
"alpha_frac": 0.6618444846,
"autogenerated": false,
"ratio": 3.6143790849673203,
"config... |
"""238. Product of Array Except Self
https://leetcode.com/problems/product-of-array-except-self/
Given an array nums of n integers where n > 1, return an array output
such that output[i] is equal to the product of all the elements of
nums except nums[i].
Example:
Input: [1,2,3,4]
Output: [24,12,8,6]
Note: Please ... | {
"repo_name": "isudox/leetcode-solution",
"path": "python-algorithm/leetcode/product_of_array_except_self.py",
"copies": "1",
"size": "1279",
"license": "mit",
"hash": -491254210865534600,
"line_mean": 27.4222222222,
"line_max": 72,
"alpha_frac": 0.5332290852,
"autogenerated": false,
"ratio": 3.7... |
"""23andme genotyping data extraction."""
from datetime import date, datetime
import json
import os
import re
from subprocess import check_output
from tempfile import TemporaryFile
import requests
SNP_DATA_23ANDME_FILE = os.path.join(
os.path.dirname(__file__),
'23andme_API_snps_data_with_ref_sorted.txt')
#... | {
"repo_name": "abramconnelly/genevieve",
"path": "file_process/utils/twentythree_and_me.py",
"copies": "4",
"size": "5716",
"license": "mit",
"hash": 5104655284128371000,
"line_mean": 36.6052631579,
"line_max": 77,
"alpha_frac": 0.5803009097,
"autogenerated": false,
"ratio": 3.244040862656073,
... |
"""2/3 compatibility module for Hyde."""
# This module is for cross-version compatibility. As such, several
# assignments and import will look invalid to checkers like flake8.
# These lines are being marked with ``# NOQA`` to allow flake8 checking
# to pass.
import sys
PY3 = sys.version_info.major == 3
if PY3:
... | {
"repo_name": "hyde/hyde",
"path": "hyde/_compat.py",
"copies": "1",
"size": "3394",
"license": "mit",
"hash": 4376309064723226600,
"line_mean": 34.7263157895,
"line_max": 72,
"alpha_frac": 0.6540954626,
"autogenerated": false,
"ratio": 4.205700123915737,
"config_test": false,
"has_no_keyword... |
# 2.3 compatibility
try:
set
except NameError:
import sets
set = sets.Set
import numpy as sp
from _delaunay import delaunay
from interpolate import LinearInterpolator, NNInterpolator
__all__ = ['Triangulation']
class Triangulation(object):
"""A Delaunay triangulation of points in a plane.
Trian... | {
"repo_name": "simion1232006/pyroms",
"path": "pyroms/delaunay/triangulate.py",
"copies": "1",
"size": "6466",
"license": "bsd-3-clause",
"hash": -1408435110932744000,
"line_mean": 36.8128654971,
"line_max": 80,
"alpha_frac": 0.6050108259,
"autogenerated": false,
"ratio": 3.5527472527472526,
"c... |
##2|3
##_|_ ##1|4
##
###use cartesian plane for dictionary
###
from myro import *
import draw
grid_position = {1: [-0.5, -0.5], 2: [-0.5, 0.5], 3: [0.5, 0.5], 4: [0.5, -0.5]}
#use c=1, d=-1 or vise versa
# 45 degree turn = 0.438
# 90 degree turn = 0.835
# 180 degree turn = 1.6478
# 360 degree turn = 3.2835
def three... | {
"repo_name": "pbardea/scribbler",
"path": "finalPrj/movement.py",
"copies": "1",
"size": "4711",
"license": "mit",
"hash": 6043197156356143000,
"line_mean": 28.8164556962,
"line_max": 98,
"alpha_frac": 0.6094247506,
"autogenerated": false,
"ratio": 3.262465373961219,
"config_test": false,
"h... |
# 24.05.2007, c
# last revision: 25.02.2008
from sfepy import data_dir
from sfepy.fem.periodic import *
filename_mesh = data_dir + '/meshes/2d/special/channels_symm944t.mesh'
if filename_mesh.find( 'symm' ):
region_1 = {
'name' : 'Y1',
'select' : """elements of group 3""",
}
region_2 = {
... | {
"repo_name": "olivierverdier/sfepy",
"path": "examples/navier_stokes/stokes.py",
"copies": "1",
"size": "4109",
"license": "bsd-3-clause",
"hash": -5551021767705433000,
"line_mean": 20.6263157895,
"line_max": 71,
"alpha_frac": 0.4366025797,
"autogenerated": false,
"ratio": 2.6821148825065273,
... |
# 24.09.2007, c
import sympy as s
##
# 25.09.2007, c
def create_scalar( name, n_ep ):
vec = s.matrices.zeronm( n_ep, 1 )
for ip in range( n_ep ):
vec[ip,0] = '%s%d' % (name, ip)
return vec
##
# 24.09.2007, c
def create_vector( name, n_ep, dim ):
"""ordering is DOF-by-DOF"""
vec = s.matrice... | {
"repo_name": "olivierverdier/sfepy",
"path": "script/evalForms.py",
"copies": "2",
"size": "7350",
"license": "bsd-3-clause",
"hash": 4083073378172863500,
"line_mean": 24.6993006993,
"line_max": 72,
"alpha_frac": 0.4968707483,
"autogenerated": false,
"ratio": 2.6231263383297643,
"config_test":... |
# 240. Search a 2D Matrix II
#
# Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
#
# Integers in each row are sorted in ascending from left to right.
# Integers in each column are sorted in ascending from top to bottom.
# For example,
#
# Consider the... | {
"repo_name": "gengwg/leetcode",
"path": "240_search_2d_matrix_ii.py",
"copies": "1",
"size": "1854",
"license": "apache-2.0",
"hash": 4798852232135010000,
"line_mean": 28.9032258065,
"line_max": 118,
"alpha_frac": 0.5685005394,
"autogenerated": false,
"ratio": 3.074626865671642,
"config_test":... |
""" 24.10.2016, fd control added to VCO. VCO does not output aything if input is zero.
Char to binary copied to be template for Binary Data Source copied """
from pyqtgraph.flowchart import Node
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.flowchart.library.common import CtrlNode
import pyqtgraph.metaar... | {
"repo_name": "Tatsi/SciEdu",
"path": "nodes.py",
"copies": "1",
"size": "28307",
"license": "mit",
"hash": 3525282142127447000,
"line_mean": 40.6310240964,
"line_max": 233,
"alpha_frac": 0.560144134,
"autogenerated": false,
"ratio": 3.6478092783505156,
"config_test": false,
"has_no_keywords"... |
# 241. Different Ways to Add Parentheses
#
# Given a string of numbers and operators, return all possible results
# from computing all the different possible ways to group numbers and operators.
# The valid operators are +, - and *.
#
# Example 1
# Input: "2-1-1".
#
# ((2-1)-1) = 0
# (2-(1-1)) = 2
# Output: [0, 2]
#
#
... | {
"repo_name": "gengwg/leetcode",
"path": "241_different_ways_to_add_parentheses.py",
"copies": "1",
"size": "1588",
"license": "apache-2.0",
"hash": 5000750482336240000,
"line_mean": 27.3571428571,
"line_max": 84,
"alpha_frac": 0.483627204,
"autogenerated": false,
"ratio": 3.260780287474333,
"c... |
""" 24.1 to 24.8 microns is Q
Hi-5:
snr.maglim([3.5,4.1], [290], diam=8, eta_c=0.4, eta_w=0.25, t_int=3600, snr=5, n_tel=4)
"""
#bp=[3.3,4.2]
#"{0:5.1f} & {1:5.1f} & {2:5.1f}".format(maglim(bp,280),maglim(bp,270),maglim(bp,220))
from __future__ import division, print_function
import numpy as np
import scipy.optimiz... | {
"repo_name": "mikeireland/pfi",
"path": "pfi/snr_back_of_envelope.py",
"copies": "1",
"size": "8587",
"license": "mit",
"hash": -4445615882068034600,
"line_mean": 38.3944954128,
"line_max": 134,
"alpha_frac": 0.6061488296,
"autogenerated": false,
"ratio": 2.629210042865891,
"config_test": fals... |
# 242. Valid Anagram
#
# Given two strings s and t, write a function to determine if t is an anagram of s.
#
# For example,
# s = "anagram", t = "nagaram", return true.
# s = "rat", t = "car", return false.
#
# Note:
# You may assume the string contains only lowercase alphabets.
#
# Follow up:
# What if the inputs ... | {
"repo_name": "gengwg/leetcode",
"path": "242_valid_anagram.py",
"copies": "1",
"size": "1332",
"license": "apache-2.0",
"hash": 105323501592310270,
"line_mean": 21.2,
"line_max": 96,
"alpha_frac": 0.4894894895,
"autogenerated": false,
"ratio": 3.338345864661654,
"config_test": false,
"has_no... |
# 247 Strobogrammatic Number II
# A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
# Find all strobogrammatic numbers that are of length = n.
# For example,
# Given n = 2, return ["11","69","88","96"].
class Solution:
def findStrobogrammatic(self, n):
... | {
"repo_name": "gengwg/leetcode",
"path": "247_strobogrammatic_number_ii.py",
"copies": "1",
"size": "1188",
"license": "apache-2.0",
"hash": 6452298081975875000,
"line_mean": 27.9756097561,
"line_max": 108,
"alpha_frac": 0.5008417508,
"autogenerated": false,
"ratio": 3.514792899408284,
"config_... |
# 249. Group Shifted Strings
# Given a string, we can "shift" each of its letter to its successive letter,
# for example: "abc" -> "bcd". We can keep "shifting" which forms the sequence:
# "abc" -> "bcd" -> ... -> "xyz"
# Given a list of strings which contains only lowercase alphabets, group all strings that belong t... | {
"repo_name": "gengwg/leetcode",
"path": "249_group_shifted_strings.py",
"copies": "1",
"size": "1034",
"license": "apache-2.0",
"hash": 4033961030151673300,
"line_mean": 26.9459459459,
"line_max": 127,
"alpha_frac": 0.5512572534,
"autogenerated": false,
"ratio": 3.1144578313253013,
"config_tes... |
""" 24 August 2017. Author: Sasha Safonova.
Script that directly calls the calcPupilMask method in DonutEngine.cc, created for development purposes only.
Be sure to compile donutengine first by:
cd ../src
make clean
make swig
make
"""
from donutlib.donutengine import donutengine
import numpy as np
from matplotlib im... | {
"repo_name": "aaronroodman/Donut",
"path": "test/testDESIpupils/checkpupil.py",
"copies": "1",
"size": "3237",
"license": "mit",
"hash": 1429703020305031400,
"line_mean": 32.3711340206,
"line_max": 109,
"alpha_frac": 0.5730614767,
"autogenerated": false,
"ratio": 3.6370786516853935,
"config_te... |
# 251. Flatten 2D Vector
# Implement an iterator to flatten a 2d vector.
# For example,
# Given 2d vector =
# [
# [1,2],
# [3],
# [4,5,6]
# ]
# By calling next repeatedly until hasNext returns false,
# the order of elements returned by next should be: [1,2,3,4,5,6].
# Hint:
# How many variables do you ... | {
"repo_name": "gengwg/leetcode",
"path": "251_flatten_2d_vector.py",
"copies": "1",
"size": "2157",
"license": "apache-2.0",
"hash": 7700662942209077000,
"line_mean": 26.3037974684,
"line_max": 89,
"alpha_frac": 0.5781177561,
"autogenerated": false,
"ratio": 3.4022082018927446,
"config_test": f... |
# 2520 is the smallest number that can be divided by each
# of the numbers from 1 to 10 without any remainder.
#
# What is the smallest positive number that is evenly
# divisible by all of the numbers from 1 to 20?
#
# Naive solution would be brute-force dividing numbers by
# 1-20 and checking for remainder, but that i... | {
"repo_name": "YangLuGitHub/Euler",
"path": "src/scripts/Problem5.py",
"copies": "1",
"size": "3564",
"license": "mit",
"hash": -5973860079645849000,
"line_mean": 33.9411764706,
"line_max": 102,
"alpha_frac": 0.6840628507,
"autogenerated": false,
"ratio": 3.173642030276046,
"config_test": false... |
# 2520 is the smallest number that can be divided by each of the numbers 1:10
# What is the smallest positive number that is evenly divisible (divisible with
# no remainder) by all of the digits 1:20
# using the concept that all numbers are "built" by primes then we can
# investigate the sum of all the prime numbers, ... | {
"repo_name": "Faraday1221/project_euler",
"path": "problem_5.py",
"copies": "1",
"size": "2017",
"license": "mit",
"hash": 3978744635409639400,
"line_mean": 37.7884615385,
"line_max": 81,
"alpha_frac": 0.6995537928,
"autogenerated": false,
"ratio": 2.9970282317979198,
"config_test": false,
"... |
#2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
#What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
# 232792560
#need to check if divisible by all primes smaller than 20, so:
# 2, 3, 5, 7, 11, 13, 17, 19
... | {
"repo_name": "ledbutter/ProjectEulerPython",
"path": "Problem5.py",
"copies": "1",
"size": "1424",
"license": "mit",
"hash": 2862918763973180400,
"line_mean": 27.7083333333,
"line_max": 107,
"alpha_frac": 0.4599719101,
"autogenerated": false,
"ratio": 2.94824016563147,
"config_test": false,
... |
# 253. Meeting Rooms II
#
# Given an array of meeting time intervals consisting of start and end times
# [[s1,e1],[s2,e2],...] (si < ei),
# find the minimum number of conference rooms required.
#
# For example,
# Given [[0, 30],[5, 10],[15, 20]],
# return 2.
class Interval(object):
def __init__(self, s=0, e=0):
... | {
"repo_name": "gengwg/leetcode",
"path": "253_meeting_rooms_ii.py",
"copies": "1",
"size": "1053",
"license": "apache-2.0",
"hash": -8847656098003055000,
"line_mean": 23.488372093,
"line_max": 76,
"alpha_frac": 0.5289648623,
"autogenerated": false,
"ratio": 3.643598615916955,
"config_test": fal... |
# 254: 11111110 254: 11111110
# 255: 11111111 1: 1
# 256: 100000000 257: 100000001
# 257: 100000001 0: 0 <- line_length = 257 - 254 + 1 = 4 % 4 = 0
# 258: 100000010 258: 100000010 <- line_length = 258 - 254 + 1 = 4 % 4 = 1
# 259: 100000011 1: 1 <- line_length... | {
"repo_name": "perlygatekeeper/glowing-robot",
"path": "google_test/queue_to_do/solution_debug_statements.py",
"copies": "1",
"size": "6011",
"license": "artistic-2.0",
"hash": 1276958955709478100,
"line_mean": 42.2446043165,
"line_max": 146,
"alpha_frac": 0.53684911,
"autogenerated": false,
"rat... |
# 25/4/2017
# This piece of code will run frames through vgg-19
# 'video_dset' = (112392,224,224,3)
# 'audio_dset' = (112392,18)
from extract_image_features.video_utils import *
import numpy as np
from extract_image_features.keras_pretrained_models.imagenet_utils import preprocess_input
from keras.models import Model
... | {
"repo_name": "schen496/auditory-hallucinations",
"path": "extract_image_features/processVideosTopAngleFC1.py",
"copies": "1",
"size": "9227",
"license": "apache-2.0",
"hash": -3527483487873842000,
"line_mean": 44.9104477612,
"line_max": 139,
"alpha_frac": 0.6479895958,
"autogenerated": false,
"r... |
# 254 Factor Combinations
# Numbers can be regarded as product of its factors. For example,
#
# 8 = 2 x 2 x 2;
# = 2 x 4.
#
# Write a function that takes an integer n and return all possible combinations of its factors.
#
# Note:
#
# You may assume that n is always positive.
# Factors should be greater than ... | {
"repo_name": "gengwg/leetcode",
"path": "254_factor_combinations.py",
"copies": "1",
"size": "1723",
"license": "apache-2.0",
"hash": -6619772164491840000,
"line_mean": 19.2705882353,
"line_max": 95,
"alpha_frac": 0.5322112594,
"autogenerated": false,
"ratio": 3.0281195079086114,
"config_test"... |
# 256. Paint House
# There are a row of n houses, each house can be painted with one of the three colors: red, blue or green.
# The cost of painting each house with a certain color is different.
# You have to paint all the houses such that no two adjacent houses have the same color.
#
# The cost of painting each house... | {
"repo_name": "gengwg/leetcode",
"path": "256_paint_house.py",
"copies": "1",
"size": "1187",
"license": "apache-2.0",
"hash": -5890696462133975000,
"line_mean": 33.8529411765,
"line_max": 106,
"alpha_frac": 0.5915611814,
"autogenerated": false,
"ratio": 2.925925925925926,
"config_test": false,... |
# 257. Binary Tree Paths
#
# Given a binary tree, return all root-to-leaf paths.
#
# For example, given the following binary tree:
#
# 1
# / \
# 2 3
# \
# 5
#
# All root-to-leaf paths are:
#
# ["1->2->5", "1->3"]
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
... | {
"repo_name": "gengwg/leetcode",
"path": "257_binary_tree_paths.py",
"copies": "1",
"size": "2079",
"license": "apache-2.0",
"hash": 1593984083958108200,
"line_mean": 24.3536585366,
"line_max": 75,
"alpha_frac": 0.5512265512,
"autogenerated": false,
"ratio": 3.465,
"config_test": false,
"has_... |
# 258. Add Digits
#
# Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
#
# For example:
#
# Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
#
# Follow up:
# Could you do it without any loop/recursion in O... | {
"repo_name": "gengwg/leetcode",
"path": "258_add_digits.py",
"copies": "1",
"size": "1415",
"license": "apache-2.0",
"hash": -5389234857446795000,
"line_mean": 24.2678571429,
"line_max": 105,
"alpha_frac": 0.5533568905,
"autogenerated": false,
"ratio": 3.5463659147869673,
"config_test": false,... |
# 259. 3Sum Smaller
# Given an array of n integers nums and a target,
# find the number of index triplets i, j, k with 0 <= i < j < k < n
# that satisfy the condition nums[i] + nums[j] + nums[k] < target.
# For example, given nums = [-2, 0, 1, 3], and target = 2.
# Return 2. Because there are two triplets which sums ... | {
"repo_name": "gengwg/leetcode",
"path": "259_3sum_smaller.py",
"copies": "1",
"size": "1475",
"license": "apache-2.0",
"hash": 2982647800105050000,
"line_mean": 28.575,
"line_max": 70,
"alpha_frac": 0.5553677092,
"autogenerated": false,
"ratio": 2.097517730496454,
"config_test": false,
"has_... |
# 26.02.2007, c
# last revision: 25.02.2008
from sfepy import data_dir
filename_mesh = data_dir + '/meshes/3d/elbow2.mesh'
options = {
'nls' : 'newton',
'ls' : 'ls',
'post_process_hook' : 'verify_incompressibility',
}
field_1 = {
'name' : '3_velocity',
'dtype' : 'real',
'shape' : (3,),
'r... | {
"repo_name": "olivierverdier/sfepy",
"path": "examples/navier_stokes/navier_stokes.py",
"copies": "1",
"size": "3826",
"license": "bsd-3-clause",
"hash": -6328635134330447000,
"line_mean": 20.138121547,
"line_max": 77,
"alpha_frac": 0.5083638265,
"autogenerated": false,
"ratio": 2.55407209612817... |
# 26.02.2007, c
# last revision: 25.02.2008
filename_mesh = 'database/pul_klikatak2.mesh'
options = {
'nls' : 'newton',
'ls' : 'ls',
'post_process_hook' : 'verify_incompressibility',
}
field_1 = {
'name' : '3_velocity',
'dim' : (3,1),
'domain' : 'Omega',
'bases' : {'Omega' : '3_4_P1B'}
}
... | {
"repo_name": "certik/sfepy",
"path": "input/navier_stokes.py",
"copies": "1",
"size": "4183",
"license": "bsd-3-clause",
"hash": -3314064456168601000,
"line_mean": 20.6735751295,
"line_max": 78,
"alpha_frac": 0.5001195314,
"autogenerated": false,
"ratio": 2.550609756097561,
"config_test": fals... |
# 260. Single Number III
#
# Given an array of numbers nums, in which exactly two
# elements appear only once and all the other elements
# appear exactly twice. Find the two elements that appear only once.
#
# For example:
#
# Given nums = [1, 2, 1, 3, 2, 5], return [3, 5].
#
# Note:
# The order of the result is not im... | {
"repo_name": "gengwg/leetcode",
"path": "260_single_number_iii.py",
"copies": "1",
"size": "1455",
"license": "apache-2.0",
"hash": -8047346649812437000,
"line_mean": 25.9444444444,
"line_max": 68,
"alpha_frac": 0.5374570447,
"autogenerated": false,
"ratio": 3.6375,
"config_test": false,
"ha... |
# 26/11/2019
import argparse
import asyncio
import multiprocessing
import sys
import threading
import time
def sleep_print(x):
time.sleep(x)
print(x)
return None
async def asleep_print(x):
await asyncio.sleep(x)
print(x)
return None
async def sleep_sort(numbers):
await asyncio.gather(*... | {
"repo_name": "tlseabra/dailyprogrammer",
"path": "Python/easy/e091.py",
"copies": "2",
"size": "1203",
"license": "mit",
"hash": -1405074483794074000,
"line_mean": 22.1346153846,
"line_max": 73,
"alpha_frac": 0.6259351621,
"autogenerated": false,
"ratio": 3.6565349544072947,
"config_test": fal... |
# 261 Graph Valid Tree
# Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes),
# write a function to check whether these edges make up a valid tree.
#
# For example:
#
# Given n = 5 and edges = [[0, 1], [0, 2], [0, 3], [1, 4]], return true.
#
# Given n = 5 and edges = [[0... | {
"repo_name": "gengwg/leetcode",
"path": "261_graph_valid_tree.py",
"copies": "1",
"size": "3466",
"license": "apache-2.0",
"hash": -5779305111753292000,
"line_mean": 39.7764705882,
"line_max": 142,
"alpha_frac": 0.5931909983,
"autogenerated": false,
"ratio": 3.418145956607495,
"config_test": f... |
# 2/6
import csv
file = open('nfl-suspensions-data.csv', 'r')
nfl_suspensions = list(csv.reader(file))
header = nfl_suspensions[0]
nfl_suspensions = nfl_suspensions[1:]
years = {}
for record in nfl_suspensions:
if record[5] in years:
years[record[5]] += 1
else:
years[record[5]] = 1
print(years,... | {
"repo_name": "my30/NFL-Suspension-DQ_Python_Intermediate-",
"path": "Analyses.py",
"copies": "1",
"size": "1206",
"license": "mit",
"hash": -683366799757733600,
"line_mean": 20.9272727273,
"line_max": 49,
"alpha_frac": 0.6053067993,
"autogenerated": false,
"ratio": 2.759725400457666,
"config_t... |
__author__ = 'Libao Jin'
__date__ = 'December 15, 2015'
class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
# s_nums = list(set(nums))
# nums.clear()
# for n in s_nums:
# nums.append(n)
... | {
"repo_name": "imthomasking/LeetCode-Solutions",
"path": "solutions/026_Remove_Duplicates_from_Sorted_Array.py",
"copies": "2",
"size": "1127",
"license": "mit",
"hash": 2132634260219477800,
"line_mean": 25.8333333333,
"line_max": 49,
"alpha_frac": 0.4480922804,
"autogenerated": false,
"ratio": 3... |
# 27/03/2017
grid = ["########=####/#",
"# | #",
"# # #",
"# # #",
"####### #",
"# _ #",
"###############"]
grid = [[c for c in grid[y]] for y in range(0, len(grid))]
coords = [(1, 1), (1, 2), (1, 3), (5, 6), (4, 2), (1, 1)... | {
"repo_name": "tlseabra/dailyprogrammer",
"path": "Python/easy/e308.py",
"copies": "2",
"size": "1296",
"license": "mit",
"hash": -3613015422583168500,
"line_mean": 31.425,
"line_max": 116,
"alpha_frac": 0.3418209877,
"autogenerated": false,
"ratio": 2.6557377049180326,
"config_test": false,
... |
# 270. Closest Binary Search Tree Value
# Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.
# Note:
# Given target value is a floating point.
# You are guaranteed to have only one unique value in the BST that is closest to the target.
class Solution:
... | {
"repo_name": "gengwg/leetcode",
"path": "270_Closest_Binary_Search_Tree_Value.py",
"copies": "1",
"size": "1161",
"license": "apache-2.0",
"hash": 4346468767855701500,
"line_mean": 39.0344827586,
"line_max": 115,
"alpha_frac": 0.6106804479,
"autogenerated": false,
"ratio": 4.102473498233215,
"... |
# 271. Encode and Decode String
# Design an algorithm to encode a list of strings to a string.
# The encoded string is then sent over the network
# and is decoded back to the original list of strings.
# Machine 1 (sender) has the function:
# string encode(vector strs) {
# // ... your code
# return encoded_stri... | {
"repo_name": "gengwg/leetcode",
"path": "271_encode_decode_string.py",
"copies": "1",
"size": "2688",
"license": "apache-2.0",
"hash": 6516824468351025000,
"line_mean": 29.4712643678,
"line_max": 88,
"alpha_frac": 0.6252830189,
"autogenerated": false,
"ratio": 3.7062937062937062,
"config_test"... |
# 276 Paint Fence
# There is a fence with n posts, each post can be painted with one of the k colors.
#
# You have to paint all the posts such that no more than two adjacent fence posts have the same color.
#
# Return the total number of ways you can paint the fence.
#
# Note:
# n and k are non-negative integers.
cla... | {
"repo_name": "gengwg/leetcode",
"path": "276_paint_fence.py",
"copies": "1",
"size": "1857",
"license": "apache-2.0",
"hash": 9178814039828115000,
"line_mean": 32.1607142857,
"line_max": 111,
"alpha_frac": 0.6322024771,
"autogenerated": false,
"ratio": 3.523719165085389,
"config_test": false,
... |
# 277. Find the Celebrity
# Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity.
# The definition of a celebrity is that all the other n - 1 people know him/her but he/she does not know any of them.
# Now you want to find out who the celebrity is or verify ... | {
"repo_name": "gengwg/leetcode",
"path": "277_find_the_celebrity.py",
"copies": "1",
"size": "2359",
"license": "apache-2.0",
"hash": -2170157446604873500,
"line_mean": 43.5094339623,
"line_max": 131,
"alpha_frac": 0.7066553624,
"autogenerated": false,
"ratio": 3.5688350983358545,
"config_test"... |
# 278. First Bad Version
#
# You are a product manager and currently leading a team to develop a new product.
# Unfortunately, the latest version of your product fails the quality check.
# Since each version is developed based on the previous version,
# all the versions after a bad version are also bad.
# Suppose y... | {
"repo_name": "gengwg/leetcode",
"path": "278_first_bad_version.py",
"copies": "1",
"size": "1572",
"license": "apache-2.0",
"hash": -5380928610539544000,
"line_mean": 31.7708333333,
"line_max": 92,
"alpha_frac": 0.5693384224,
"autogenerated": false,
"ratio": 3.7517899761336517,
"config_test": ... |
# 279. Perfect Squares
# Given a positive integer n, find the least number of perfect square numbers
# (for example, 1, 4, 9, 16, ...) which sum to n.
# For example, given n = 12, return 3 because 12 = 4 + 4 + 4;
# given n = 13, return 2 because 13 = 4 + 9.
class Solution(object):
# https://gengwg.blogspot.com/2... | {
"repo_name": "gengwg/leetcode",
"path": "279_perfect_squares.py",
"copies": "1",
"size": "1692",
"license": "apache-2.0",
"hash": -3661270329295339000,
"line_mean": 29.7636363636,
"line_max": 82,
"alpha_frac": 0.4645390071,
"autogenerated": false,
"ratio": 3.253846153846154,
"config_test": fal... |
# 280. Wiggle Sort
# Given an unsorted array nums, reorder it in-place such that
# nums[0] <= nums[1] >= nums[2] <= nums[3]....
# For example, given nums = [3, 5, 2, 1, 6, 4],
# one possible answer is [1, 6, 2, 5, 3, 4].
# the pattern is number in odd position is peak.
# First try to solve it without in-place:
#... | {
"repo_name": "gengwg/leetcode",
"path": "280_wiggle_sort.py",
"copies": "1",
"size": "2247",
"license": "apache-2.0",
"hash": -2238701915889132800,
"line_mean": 35.3333333333,
"line_max": 94,
"alpha_frac": 0.5479577788,
"autogenerated": false,
"ratio": 2.87467018469657,
"config_test": false,
... |
# 283. Move Zeroes
# Given an array nums, write a function to move all 0's to the end of it
# while maintaining the relative order of the non-zero elements.
# For example, given nums = [0, 1, 0, 3, 12],
# after calling your function, nums should be [1, 3, 12, 0, 0].
class Solution(object):
# http://bookshadow.c... | {
"repo_name": "gengwg/leetcode",
"path": "283_move_zeros.py",
"copies": "1",
"size": "1115",
"license": "apache-2.0",
"hash": -7556605429947354000,
"line_mean": 27.3714285714,
"line_max": 74,
"alpha_frac": 0.5760322256,
"autogenerated": false,
"ratio": 2.4101941747572817,
"config_test": false,
... |
# 284. Peeking Iterator
# Given an Iterator class interface with methods: next() and hasNext(),
# design and implement a PeekingIterator that support the peek() operation --
# it essentially peek() at the element that will be returned by the next call to next().
# Here is an example.
# Assume that the iterator is ... | {
"repo_name": "gengwg/leetcode",
"path": "284_peeking_iterator.py",
"copies": "1",
"size": "3302",
"license": "apache-2.0",
"hash": 7717044264119823000,
"line_mean": 29.1495327103,
"line_max": 102,
"alpha_frac": 0.6301921885,
"autogenerated": false,
"ratio": 3.7730994152046784,
"config_test": f... |
# 28684
P = 4
MB = 10 ** P
MA = MB / 10
def poly3(n):
return n * (n + 1) / 2
def poly4(n):
return n * n
def poly5(n):
return n * (3 * n - 1) / 2
def poly6(n):
return n * (2 * n - 1)
def poly7(n):
return n * (5 * n - 3) / 2
def poly8(n):
return n * (3 * n - 2)
polyf = [poly3, poly4, poly5, poly... | {
"repo_name": "higgsd/euler",
"path": "py/61.py",
"copies": "1",
"size": "1043",
"license": "bsd-2-clause",
"hash": 835883291153181600,
"line_mean": 21.1914893617,
"line_max": 63,
"alpha_frac": 0.4458293384,
"autogenerated": false,
"ratio": 2.5254237288135593,
"config_test": false,
"has_no_ke... |
# 286. WALLS AND GATES
# You are given a m x n 2D grid initialized with these three possible values.
#
# -1 – A wall or an obstacle.
# 0 – A gate.
# INF – Infinity means an empty room.
# We use the value 2^31 - 1 = 2147483647 to represent INF
# as you may assume that the distance to a gate is less than 2147483647.
# ... | {
"repo_name": "gengwg/leetcode",
"path": "286_walls_and_gates.py",
"copies": "1",
"size": "2059",
"license": "apache-2.0",
"hash": -3065197513937188400,
"line_mean": 28.1194029851,
"line_max": 93,
"alpha_frac": 0.5381855459,
"autogenerated": false,
"ratio": 2.661664392905866,
"config_test": fal... |
# 287. Find the Duplicate Number
# Given an array nums containing n + 1 integers
# where each integer is between 1 and n (inclusive),
# prove that at least one duplicate number must exist.
# Assume that there is only one duplicate number, find the duplicate one.
# Note:
# You must not modify the array (assume th... | {
"repo_name": "gengwg/leetcode",
"path": "287_find_duplicate_number.py",
"copies": "1",
"size": "2769",
"license": "apache-2.0",
"hash": 917608630373290500,
"line_mean": 26.5063291139,
"line_max": 95,
"alpha_frac": 0.5605154165,
"autogenerated": false,
"ratio": 2.1600397614314115,
"config_test"... |
# 288 Unique Word Abbreviation
# An abbreviation of a word follows the form <first letter><number><last letter>.
# Below are some examples of word abbreviations:
# a) it --> it (no abbreviation)
# 1
# b) d|o|g --> d1g
# 1 1 1
# 1---5----0----5--... | {
"repo_name": "gengwg/leetcode",
"path": "288_unique_word_abbreviation.py",
"copies": "1",
"size": "2499",
"license": "apache-2.0",
"hash": -1585880891068679400,
"line_mean": 31,
"line_max": 102,
"alpha_frac": 0.5715430862,
"autogenerated": false,
"ratio": 3.519040902679831,
"config_test": fals... |
# 289. Game of Life
# According to the Wikipedia's article:
# "The Game of Life, also known simply as Life, is a cellular automaton
# devised by the British mathematician John Horton Conway in 1970."
# Given a board with m by n cells, each cell has an initial state live (1) or dead (0).
# Each cell interacts with ... | {
"repo_name": "gengwg/leetcode",
"path": "289_game_of_life.py",
"copies": "1",
"size": "3627",
"license": "apache-2.0",
"hash": 6601479205694009000,
"line_mean": 40.2159090909,
"line_max": 103,
"alpha_frac": 0.6076647367,
"autogenerated": false,
"ratio": 3.7546583850931676,
"config_test": false... |
# 28. Implement `strstr()`.
#
# Return the index of the first occurrence of needle in haystack, or -1
# if needle is not part of haystack. If `needle` is empty, return 0
# (consistent with `strstr` in C).
# My original, basic solution exceeded the time limit, so I had to
# implement some more complicated solutions.
... | {
"repo_name": "afbarnard/glowing-broccoli",
"path": "lc/000028.py",
"copies": "1",
"size": "3390",
"license": "mit",
"hash": -2198578655039251500,
"line_mean": 29.8181818182,
"line_max": 72,
"alpha_frac": 0.5666666667,
"autogenerated": false,
"ratio": 3.162313432835821,
"config_test": false,
... |
#29-04-04
# v1.0.1
# E-mail fuzzyman AT atlantibots DOT org DOT uk (or michael AT foord DOT me DOT uk )
# Maintained at www.voidspace.org.uk/atlantibots/pythonutils.html
# Used by COnfigObj for storing config files with lists of values.
def listparse(inline, recursive = 1, comment = 1, retain = 0, lpstack = None, **ke... | {
"repo_name": "ActiveState/code",
"path": "recipes/Python/281056_Listparse/recipe-281056.py",
"copies": "1",
"size": "11198",
"license": "mit",
"hash": 5740477960296902000,
"line_mean": 41.4166666667,
"line_max": 166,
"alpha_frac": 0.595106269,
"autogenerated": false,
"ratio": 4.37421875,
"conf... |
# 290. Word Pattern
# Given a pattern and a string str, find if str follows the same pattern.
# Here follow means a full match, such that there is a bijection
# between a letter in pattern and a non-empty word in str.
# Examples:
# pattern = "abba", str = "dog cat cat dog" should return true.
# pattern = "a... | {
"repo_name": "gengwg/leetcode",
"path": "290_word_pattern.py",
"copies": "1",
"size": "2495",
"license": "apache-2.0",
"hash": -4263764307193054000,
"line_mean": 25.8279569892,
"line_max": 85,
"alpha_frac": 0.5190380762,
"autogenerated": false,
"ratio": 3.4846368715083798,
"config_test": false... |
# 292. Nim Game
# You are playing the following Nim Game with your friend:
# There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones.
# The one who removes the last stone will be the winner.
# You will take the first turn to remove the stones.
# Both of you are very clever a... | {
"repo_name": "gengwg/leetcode",
"path": "292_nim_game.py",
"copies": "1",
"size": "1475",
"license": "apache-2.0",
"hash": 8900999323890607000,
"line_mean": 25.4418604651,
"line_max": 99,
"alpha_frac": 0.6640281442,
"autogenerated": false,
"ratio": 1.8700657894736843,
"config_test": false,
"... |
# 294. Flip Game II
# You are playing the following Flip Game with your friend:
# Given a string that contains only these two characters: + and -,
# you and your friend take turns to flip twoconsecutive "++" into "--".
# The game ends when a person can no longer make a move and therefore the other person will be the w... | {
"repo_name": "gengwg/leetcode",
"path": "294_flip_game_ii.py",
"copies": "1",
"size": "2261",
"license": "apache-2.0",
"hash": 6868286891973164000,
"line_mean": 29.9726027397,
"line_max": 106,
"alpha_frac": 0.5095090668,
"autogenerated": false,
"ratio": 3.583201267828843,
"config_test": false,... |
# 295 - Find Median From Data Stream (Hard)
# https://leetcode.com/problems/find-median-from-data-stream/
import heapq
class MedianFinder:
def __init__(self):
"""
Initialize your data structure here.
"""
self.lower = []
self.higher = []
def addNum(self, num):
... | {
"repo_name": "zubie7a/Algorithms",
"path": "LeetCode/03_Hard/lc_295.py",
"copies": "1",
"size": "3481",
"license": "mit",
"hash": -748537989282124800,
"line_mean": 38.1235955056,
"line_max": 79,
"alpha_frac": 0.5564492962,
"autogenerated": false,
"ratio": 3.6565126050420167,
"config_test": fal... |
# 297. Serialize and Deserialize Binary Tree
# Serialization is the process of converting a data structure or object into a sequence of bits
# so that it can be stored in a file or memory buffer, or transmitted across a network connection link
# to be reconstructed later in the same or another computer environment.
#... | {
"repo_name": "gengwg/leetcode",
"path": "297_serialize_deserialize_binary_tree.py",
"copies": "1",
"size": "2698",
"license": "apache-2.0",
"hash": -5026139774030140000,
"line_mean": 31.5060240964,
"line_max": 122,
"alpha_frac": 0.6282431431,
"autogenerated": false,
"ratio": 3.9101449275362317,
... |
# 298: Binary Tree Longest Consecutive Sequence
# Given a binary tree, find the length of the longest consecutive sequence path.
# The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections.
# The longest consecutive path need to be from parent to chil... | {
"repo_name": "gengwg/leetcode",
"path": "298_binary_tree_longest_consecutive_sequence.py",
"copies": "1",
"size": "1969",
"license": "apache-2.0",
"hash": -2621443725964650000,
"line_mean": 26.3194444444,
"line_max": 127,
"alpha_frac": 0.5851550585,
"autogenerated": false,
"ratio": 3.61580882352... |
"""2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order
and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
"""
# Definition f... | {
"repo_name": "nadesico19/nadepy",
"path": "leetcode/algo_2_add_two_numbers.py",
"copies": "1",
"size": "1229",
"license": "mit",
"hash": 3944211339882085400,
"line_mean": 24.7173913043,
"line_max": 108,
"alpha_frac": 0.5077298617,
"autogenerated": false,
"ratio": 3.404432132963989,
"config_tes... |
""" 2: Algorithms
thomas moll 2015
"""
import time, random
def find_sequentially(arr, item):
""" Sequential Search
Complexity: O(n)
"""
for value, i in enumerate(arr):
# Check each item in the list
if item == value: #Runs N number of times
... | {
"repo_name": "huiyi1990/Data-Structure-Zoo",
"path": "1-Algorithm Analysis/algorithms.py",
"copies": "9",
"size": "2193",
"license": "mit",
"hash": -6634006161716739000,
"line_mean": 23.8,
"line_max": 66,
"alpha_frac": 0.5125398997,
"autogenerated": false,
"ratio": 3.9584837545126352,
"config_... |
# Create a dictionary of headers containing our Authorization header.
headers = {"Authorization": "token 1f36137fbbe1602f779300dad26e4c1b7fbab631"}
# Make a GET request to the GitHub API with our headers.
# This API endpoint will give us details about Vik Paruchuri.
response = requests.get("https://api.github.com/use... | {
"repo_name": "vipmunot/Data-Analysis-using-Python",
"path": "Apis and Scraping/Intermediate APIs-118.py",
"copies": "1",
"size": "2765",
"license": "mit",
"hash": 2526848869270532000,
"line_mean": 40.2835820896,
"line_max": 133,
"alpha_frac": 0.7446654611,
"autogenerated": false,
"ratio": 3.3434... |
## 2. Array Comparisons ##
countries_canada = (world_alcohol[:,2] == 'Canada')
years_1984 = (world_alcohol[:,0] == '1984')
## 3. Selecting Elements ##
country_is_algeria = (world_alcohol[:,2] == 'Algeria')
country_algeria = world_alcohol[country_is_algeria,:]
## 4. Comparisons with Multiple Conditions ##
is_algeri... | {
"repo_name": "vipmunot/Data-Analysis-using-Python",
"path": "Data Analysis with Pandas Intermediate/Computation with NumPy-169.py",
"copies": "1",
"size": "2088",
"license": "mit",
"hash": -2203936551186162700,
"line_mean": 28.8428571429,
"line_max": 108,
"alpha_frac": 0.6685823755,
"autogenerated... |
headers = {"Authorization": "bearer 13426216-4U1ckno9J5AiK72VRbpEeBaMSKk", "User-Agent": "Dataquest/1.0"}
params = {"t": "day"}
response = requests.get("https://oauth.reddit.com/r/python/top", headers=headers, params=params)
python_top = response.json()
## 3. Getting the Most Upvoted Post ##
python_top_articles = p... | {
"repo_name": "vipmunot/Data-Analysis-using-Python",
"path": "Apis and Scraping/Challenge_ Working with the reddit API-183.py",
"copies": "1",
"size": "1477",
"license": "mit",
"hash": -6792270547959599000,
"line_mean": 31.8444444444,
"line_max": 105,
"alpha_frac": 0.682464455,
"autogenerated": fal... |
#2boom (c) 2013
# v.0.4 03.04.13
from Poll import Poll
from Components.Converter.Converter import Converter
from enigma import iServiceInformation, iPlayableService
from Components.Element import cached
class ServiceInfoEX(Poll, Converter, object):
apid = 0
vpid = 1
sid = 2
onid = 3
tsid = 4
prcpid = 5
caids = ... | {
"repo_name": "Franc1/Enigma2-Skin-MetropolisHD",
"path": "usr/lib/enigma2/python/Components/Converter/ServiceInfoEX.py",
"copies": "1",
"size": "6968",
"license": "mit",
"hash": -5584527890525623000,
"line_mean": 37.4972375691,
"line_max": 230,
"alpha_frac": 0.6671928817,
"autogenerated": false,
... |
"""2-by-2 contingency tables and scores"""
# Copyright (c) 2017 Aubrey Barnard. This is free software released
# under the MIT license. See LICENSE for details.
import math
class TwoByTwoTable(object):
"""Traditional 2-by-2 table as used in epidemiology, etc. to compare
exposures and outcomes
"""
... | {
"repo_name": "afbarnard/barnapy",
"path": "barnapy/contingency_table.py",
"copies": "1",
"size": "10557",
"license": "mit",
"hash": -7399744215904303000,
"line_mean": 35.2783505155,
"line_max": 77,
"alpha_frac": 0.548924884,
"autogenerated": false,
"ratio": 3.6216123499142365,
"config_test": f... |
## 2. Calculating differences ##
female_diff = (10771 - 16280.5)/16280.5
male_diff = (21790 - 16280.5)/16280.5
## 3. Updating the formula ##
female_diff = ((10771 - 16280.5)**2)/16280.5
male_diff = ((21790 - 16280.5)**2)/16280.5
gender_chisq = male_diff + female_diff
## 4. Generating a distribution ##
chi_squared_... | {
"repo_name": "vipmunot/Data-Analysis-using-Python",
"path": "Probability Statistics Intermediate/Chi-squared tests-172.py",
"copies": "1",
"size": "1994",
"license": "mit",
"hash": -8926437852918459000,
"line_mean": 24.5769230769,
"line_max": 60,
"alpha_frac": 0.6293881645,
"autogenerated": false,... |
## 2. Calculating expected values ##
males_over50k = .241 * .669 * 32561
males_under50k = .759 * .669 * 32561
females_over50k = .241 * .331 * 32561
females_under50k = .759 * .331 * 32561
## 3. Calculating chi-squared ##
observed = [6662, 1179, 15128, 9592]
expected = [5249.8, 2597.4, 16533.5, 8180.3]
values = []
fo... | {
"repo_name": "vipmunot/Data-Analysis-using-Python",
"path": "Probability Statistics Intermediate/Multi category chi-squared tests-173.py",
"copies": "1",
"size": "1045",
"license": "mit",
"hash": -7487479239693211000,
"line_mean": 23.3255813953,
"line_max": 71,
"alpha_frac": 0.6880382775,
"autogen... |
"""2ch bbs response decoder.
Copyright (c) 2011-2014 mei raka
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list... | {
"repo_name": "meiraka/python-bbs2ch",
"path": "bbs2ch/decode.py",
"copies": "1",
"size": "4316",
"license": "bsd-3-clause",
"hash": 5503994917018954000,
"line_mean": 35.5762711864,
"line_max": 79,
"alpha_frac": 0.6320667285,
"autogenerated": false,
"ratio": 3.9560036663611364,
"config_test": f... |
#2C_LCD_driver.py is needed https://gist.github.com/vay3t/8b0577acfdb27a78101ed16dd78ecba1
#put it in the same folder
#add your ethereum address to eth_adress
#donate to 0x9c64Fd2804730683F3c5401aBA7285b2f33F3eDF or not , I'll live
import I2C_LCD_d... | {
"repo_name": "Ilyab99/HodlBot90000",
"path": "text-requests.py",
"copies": "1",
"size": "3510",
"license": "bsd-2-clause",
"hash": -8823703559330940000,
"line_mean": 38.8863636364,
"line_max": 227,
"alpha_frac": 0.6512820513,
"autogenerated": false,
"ratio": 3.243992606284658,
"config_test": f... |
## 2. Condensing class size ##
class_size = data['class_size']
class_size = class_size[class_size['GRADE ']=='09-12']
class_size = class_size[class_size['PROGRAM TYPE']=='GEN ED']
print(class_size.head(5))
## 3. Computing average class sizes ##
import numpy
class_size = class_size.groupby("DBN").agg(numpy.mean)
clas... | {
"repo_name": "vipmunot/Data-Analysis-using-Python",
"path": "Data Exploration/Data Cleaning Walkthrough_ Combining The Data-209.py",
"copies": "1",
"size": "1975",
"license": "mit",
"hash": -6883235805608522000,
"line_mean": 31.393442623,
"line_max": 132,
"alpha_frac": 0.6901265823,
"autogenerated... |
# 2 conditional execution: if
# 2 alternative execution: if else
# 2 chained conditonals: if else elif
# raw input
# 4 def 1 bool 1 int 1 str 1 whatever you want
# main
# comparison conditionals
# or / not conditionals
# random.random = 0 to 1
# random.randint()
# str.format()
# """
def dying_age(age):
a... | {
"repo_name": "suay1936/suay1936-cmis-cs2",
"path": "conditionals1.py",
"copies": "1",
"size": "2143",
"license": "cc0-1.0",
"hash": -3933921182750078000,
"line_mean": 29.1830985915,
"line_max": 150,
"alpha_frac": 0.615025665,
"autogenerated": false,
"ratio": 3.5776293823038396,
"config_test": ... |
# 2-corner diag cvx quads
import numpy
import fractions
# upper half z
n = 2
m = 2
nn = max(n,m)
diag_gcd_sums = []
for i in xrange(0, n + 1):
diag_gcd_sums.append([]) # j = 0
for j in xrange(0, m + 1):
# if (j, i) == (5, 3):
# pdb.set_trace()
if i == 0 or j == 0 or j == m or ((... | {
"repo_name": "bgwines/project-euler",
"path": "src/in progress/1-corner-quads.py",
"copies": "1",
"size": "3812",
"license": "bsd-3-clause",
"hash": -7078288630280940000,
"line_mean": 27.447761194,
"line_max": 140,
"alpha_frac": 0.3911332634,
"autogenerated": false,
"ratio": 2.1782857142857144,
... |
# 2. Create build/pyglet.wxs from pyglet.wxs, add all file components
# 3. Run candle and light on build/pyglet.wxs to generate
# ../../dist/pyglet.msi
import os
import re
import shutil
import subprocess
from uuid import uuid1
from xml.dom.minidom import parse
import pkg_resources
class PythonVersion:
def __in... | {
"repo_name": "bitcraft/pyglet",
"path": "tools/genmsi/genmsi.py",
"copies": "1",
"size": "11530",
"license": "bsd-3-clause",
"hash": 7561299394476157000,
"line_mean": 33.833836858,
"line_max": 159,
"alpha_frac": 0.5662619254,
"autogenerated": false,
"ratio": 3.732599546778893,
"config_test": f... |
# 2. Create build/pyglet.wxs from pyglet.wxs, add all file components
# 3. Run candle and light on build/pyglet.wxs to generate
# ../../dist/pyglet.msi
import os
import re
import shutil
import subprocess
from uuid import uuid1
from xml.dom.minidom import parse
import pkg_resources
class PythonVersion... | {
"repo_name": "google-code-export/pyglet",
"path": "tools/genmsi/genmsi.py",
"copies": "26",
"size": "11619",
"license": "bsd-3-clause",
"hash": 9195530746191608000,
"line_mean": 34.7689873418,
"line_max": 136,
"alpha_frac": 0.5622686978,
"autogenerated": false,
"ratio": 3.71808,
"config_test":... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.