blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 545k | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 545k |
|---|---|---|---|---|---|---|
a5df002d45d309cf73a798b541081a6264068e26 | R-ISWARYA/python | /natural number.py | 71 | 3.765625 | 4 | x=int(input("s="))
sum=0
for x in range (1,n+1):
sum=sum+x
print(sum)
|
5c0ad55c6bc5a2f224e29d98a523f9d4f36143b1 | R-ISWARYA/python | /prime or not 13.py | 187 | 3.640625 | 4 | N=int(input("NUMBER="))
if(N<=1000):
flag=0
for x in range(1,N+1):
if(N%x==0):
flag=flag+1
if(flag==2):
print("PRIME")
else:
print("NOT A PRIME")
else:
print("the input size is invalid")
|
9745f28c593690bc031f31583fcc09b759215909 | Mingchenchen/mindsdb | /test.py | 531 | 3.859375 | 4 | from mindsdb import Predictor
# We tell mindsDB what we want to learn and from what data
mdb = Predictor(name='home_rentals_price')
mdb.learn(
to_predict='rental_price', # the column we want to learn to predict given all the data in the file
from_data="https://s3.eu-west-2.amazonaws.com/mindsdb-example-data/... |
3ee2c5e19e0ecc12ad2936a8f7486e258e8f5af2 | bb2qqq/tech_notes | /THEORIES/algorithm/leetcode/N118_Pascal_Triangle.py | 1,413 | 4.0625 | 4 | # coding: utf-8
"""
Link: https://leetcode.com/problems/pascals-triangle/
Description:
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
[1,5,10,10,5,1]
[1,6,15,2... |
6f4cef29f4678a8f063c2f29954846cafc84b06f | bb2qqq/tech_notes | /THEORIES/algorithm/leetcode/Y257_Binary_Tree_Paths.py | 5,288 | 3.59375 | 4 | # coding: utf-8
"""
Link: https://leetcode.com/problems/binary-tree-paths/
Description:
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"]
"""
# 看到此题,脑海里... |
c20dd37e04331695e72078e53f418d77dc681bc4 | bb2qqq/tech_notes | /THEORIES/math/PROBABILITY/tool.py | 1,207 | 3.796875 | 4 | def single_match_probs(team1, team2):
""" input: team1 general winning P, team2 general winning P
return: team1 winning probability versus team2.
"""
ability_1 = team1/(1-team1)
ability_2 = team2/(1-team2)
return ability_1 / (ability_1+ability_2)
def multiple_match_probs(single_P1, max_matc... |
ab47589691cffb642b2842c02931a745bf4e61e4 | bb2qqq/tech_notes | /THEORIES/algorithm/leetcode/Y242_Valid_Anagram.py | 1,607 | 3.953125 | 4 | # coding: utf-8
"""
Link: https://leetcode.com/problems/valid-anagram/
Description:
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 ... |
ab0cbd810e90b0083894b12ff997d8588cb7bf91 | bb2qqq/tech_notes | /THEORIES/algorithm/exercise/simple_recursion.py | 770 | 3.515625 | 4 | # coding: utf-8
import random
def ban_shi():
your_word=raw_input("你:")
if your_word == '我爸是那谁谁':
print '好的,您先坐会,马上就好!'
return
else:
excuse=random.choice(['对不起,按规定这个不能办。', '我们现在不办公,下个星期二再来吧。', '星期二我们内部交流,不对外办公。',
'你找XX局吧。', '你的证件不齐。', '这不是我们负责范围', '我们只接受网上预约。', '我们网上预约... |
58e95738dbc3a0345a8a560aed9cb69d817e00c6 | bb2qqq/tech_notes | /LANGUAGES/python_mania/unsort/practice_work/binary_search.py | 853 | 3.515625 | 4 | L = [1,4,5]
def bs(seq, num, lower_limit=0, up_limit=None):
""" find the pos of a num in a sorted list """
if up_limit == None:
up_limit = len(seq) - 1
print lower_limit, up_limit
mid = (up_limit + lower_limit)//2
if num == seq[mid]:
return mid
if up_limit - lower_limit == 1... |
ff447062ab6f7218ed651ba425a51a89569f4b97 | bb2qqq/tech_notes | /THEORIES/algorithm/leetcode/Y258_Add_Digits.py | 2,698 | 3.90625 | 4 | # coding: utf-8
"""
Link: https://leetcode.com/problems/add-digits/
Description:
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 y... |
82588566f90cd5e3e1e20189cb14c27de5908220 | vibhorsingh11/hackerrank-python | /04_Sets/13_CheckStrictSuperset.py | 386 | 3.859375 | 4 | # You are given a set A and N other sets.
# Your job is to find whether set A is a strict superset of each of the N sets.
#
# Print True, if A is a strict superset of each of the N sets. Otherwise, print False.
#
# A strict superset has at least one element that does not exist in its subset.
a = set(input().split())
... |
9c738875350bec148a14096eec94605fe89c99b0 | vibhorsingh11/hackerrank-python | /04_Sets/02_SymmetricDifference.py | 467 | 4.3125 | 4 | # Given 2 sets of integers, M and N, print their symmetric difference in ascending order. The term symmetric difference indicates
# those values that exist in either M or N but do not exist in both.
# Enter your code here. Read input from STDIN. Print output to STDOUT
a, b = (int(input()), input().split())
c, d = (int... |
2d7739e9bcaab75d200646afe3ab634995cf9c7f | vibhorsingh11/hackerrank-python | /03_Strings/14_MergeTheTools.py | 1,094 | 3.890625 | 4 | # Consider the following:
#
# A string, s, of length n where s=c0c1c2....cn. An integer, k, where is a factor of n.
#
# We can split s into n/k subsegments where each subsegment, t, consists of a contiguous block of k characters in s.
# Then, use each t to create string u such that:
#
# The characters in u are a subse... |
2d20f9246d49929f50a3f1a18994a7f1f5615bc3 | ziadsherif3/8-Puzzle-Game-AI | /A_search.py | 6,985 | 3.59375 | 4 | import heapq
import math
import time
MANHATTAN = 1
EUCLIDEAN = 2
class Board():
def __init__(self, confg, cost_type, parent, cost):
self.confg = confg
self.cost_type = cost_type
self.parent = parent
self.cost = cost
self.total_cost = self.cal_total_cost(cost)
def c... |
c790f49fdfa7cf8ffd1da7ad752f5046c825cbbc | Ekl1p5e/Mappers | /reducer2.py | 989 | 3.6875 | 4 | #!/usr/bin/env python
# Be sure the indentation is correct and also be sure the line above this is on the first line
import sys
def main(argv):
# Initialize variables
current_word = None
current_count = 0
word = None
# Loop through lines of the standard input
for line in sys.stdin:
# Trim line
... |
a8e3dca781283508d432cc5481c47eb19da5f294 | yashmantri20/Dsa-In-Python | /Array/Array2.py | 171 | 3.671875 | 4 | # Find the "Kth" max and min element of an array
a = [2,5,1,8,3,7,9]
K = 2
# Directly
a.sort()
print(a[K - 1],a[len(a) - K])
# if no direct function then use merge sort |
c40e300412196074c6f1662e1188ccd30814c83d | yashmantri20/Dsa-In-Python | /Array/Array18.py | 196 | 3.640625 | 4 | # find common elements In 3 sorted arrays
class Solution:
def commonElements (self,A, B, C, n1, n2, n3):
l = []
arr = sorted(list(set(A) & set(B) & set(C)))
return arr |
8dd179fe0e998c392c44a410e74df3ba30ebf341 | Dzoiver/seifer_sort | /App.py | 2,301 | 3.546875 | 4 | import tkinter as tk
from tkinter import filedialog
import os
class App:
def __init__(self):
self.HEIGHT = 150
self.WIDTH = 400
self.dir = ''
self.application_window = tk.Tk()
self.entry = tk.Entry()
def dialog_open(self):
self.dir = filedialog.askdirectory(par... |
08436f0f7a0fc1c647fec94708945a9608c7224a | fouad89/big-data-processing | /inversion_count.py | 391 | 3.9375 | 4 | def count_inversions(my_array):
# create output variable
res = 0
size = len(my_array)
for i in range(size-1):
for j in range(i+1, size):
# print(i, end=',')
# print(j)
if (my_array[i] > my_array[j]):
res+=1
return res
if __name__ == '__... |
7276c10f1e342e0f6ca8170a299fc4471cd955a6 | menasheep/CodingDojo | /Python/compare_arrays.py | 1,165 | 4.15625 | 4 | list_one = [1,2,5,6,2]
list_two = [1,2,5,6,2]
if list_one == list_two:
print True
print "These arrays are the same!"
else:
print False
print "These arrays are different. Womp womp."
# *****
list_one = [1,2,5,6,5]
list_two = [1,2,5,6,5,3]
if list_one == list_two:
print True
print "These array... |
d409ab5bf0dc56aaa62c183b934f311797e24c16 | AlexDevyatov/ACM-Contests-Data | /NCPC/2014/ncpc2014/clockpictures/submissions/time_limit_exceeded/hex539-strstr.py | 796 | 3.75 | 4 | #!/usr/bin/env python
#
# Author
# Robin Lee (hex539)
#
# Algorithm
# Convert each clock to a string representation. If they both convert to
# the same cyclic string then the clocks are identical. We do this by
# first checking the lengths are the same then seeing if one string is
# a substring of the other ... |
1b8b962aa783d91298d9abb7925dca5638591fc3 | shubhamm033/googlepython | /helper.py | 1,206 | 4.03125 | 4 | # filename='alice.txt'
# file=open(filename,'r')
# for steps in file:
# print(steps.split())
def word_count_dict(filename):
"""Returns a word/count dict for this filename."""
# Utility used by count() and Topcount().
word_count = {} # Map each word to its count
input_file = open(filename, 'r')
for l... |
17cf29555431657c45903cb1ef9518869ba558d1 | shubhamm033/googlepython | /tuple.py | 208 | 3.953125 | 4 | loo=[(1,2,6),(1,4,5),(7,8,9)]
def lastelement():
list=[]
for tuple in loo:
n=tuple[-1]
list.append(n)
list.sort()
return list
print(sorted(loo,key=list)) |
d870d0ae1b29fd296f7e5ccc629022da58d77175 | mohitj2401/python | /asignment 1/2.py | 88 | 4.09375 | 4 | # area of a circle
radius=float(input("Enter Radius"))
area=3.14*(radius**2)
print(area) |
77e5121d089bcd6301d3e2a727552711df3a70a5 | mohitj2401/python | /uses of tkinker/canvas.py | 259 | 3.5625 | 4 | from tkinter import *
window=Tk()
c=Canvas(window,width=300,height=300)
c.pack()
c.create_line(0,0,300,300,fill="red")
c.create_line(300,0,0,300,fill="red")
c.create_rectangle(0,0,100,100 ,fill="red")
c.create_oval(10,10,100,100,fill="red")
window.mainloop()
|
d05283ec02763bbfb050ebf10c487d163e41d304 | MoonWatcher582/KTB | /intro.py | 916 | 3.8125 | 4 | from pygame import *
from utils import scrollText
def intro():
display.set_mode((800, 500))
text = """In a distant hamlet, the village priest prepares the rites.
As he knows, the Fertility Goddess has promised prosperity
so long as each hamlet baby is baptized in her name.
Without the ritu... |
994280f67651b8147d56125ab99aa4ed7b1b606c | kdoeun/python | /Ch03/3_2_While.py | 812 | 3.609375 | 4 | """
날짜 : 2021/08/10
이름 : 김도은
내용 : 파이썬 while문 실습하기 교재 p64
"""
# while
num = 1
while num < 5:
print('%d회 반복' % num)
num += 1
# 1부터 10까지 합
tot, k = 0, 1
while k <= 10:
tot += k
k += 1
print('1부터 10까지의 합 :', tot)
# 1부터 10까지 짝수합
total, j = 0, 1
while j <= 10:
if j % 2 == 0:
total += j
... |
c3e6ccc608778ee291297423f1243eaea0218b6d | red3141/ProjectEuler | /P18.py | 1,093 | 3.703125 | 4 | from Utils import readIntegerTriangle
def P18():
triangle = readIntegerTriangle(
"75 "
"95 64 "
"17 47 82 "
"18 35 87 10 "
"20 04 82 47 65 "
"19 01 23 75 03 34 "
"88 02 77 73 07 63 67 "
"99 65 04 28 06 16 70 92 "
"41 41 26 56 83 40 80 70 33 "
"41 48 72 33 4... |
d160e9fb05d5a82674ae874feb38845d01e614c3 | red3141/ProjectEuler | /P33.py | 675 | 3.875 | 4 | from fractions import Fraction
def P33():
product = Fraction(1, 1)
for n in range(10, 99):
for d in range(n + 1, 100):
# Skip trivial examples of these types of fractions.
if n % 10 == 0 and d % 10 == 0:
continue
f = Fraction(n, d)
n1 = n / 10
n2 = n % 10
d1 = d /... |
399f53f673d4616afd008119667b79d0054ecdb3 | mahmdy/CryptScript | /encrypt_files.py | 1,281 | 3.703125 | 4 | import os
import shutil
from cryptography.fernet import Fernet
# Read the encryption key from the 'key' file
with open('key', 'rb') as key_file:
encryption_key = key_file.read()
# Remove the 'key' file
# os.remove('key')
# Create an instance of the encryption cipher
cipher = Fernet(encryption_key)
# Get the cur... |
ec7a3f5bbbb53fcb8a57cf74c2f8f39c1fb38b9f | ne-il/multiprocessing_image_scraper | /multiprocess_imagescrapper.py | 5,754 | 3.640625 | 4 | """
This module allows the user to scrap every image from a list of url using multiprocessing.
The main motivation for using multiprocessing are:
- Scrapping data from website involve a lot of HTTP request which
are very execution time consuming if done sequentially.
- Delegating heavy file I/O operation to wo... |
fcb0c50949411625931b2dc927325ea0424a0a37 | Navyakethavath/Python_Flask_Assignments | /Day3.py | 455 | 4.03125 | 4 | #AGE CALCULATOR
x=int(input("enter the year of the birth of the user:"))
y=2021
age=y-x
print(age)
#Simple Calculator:
a = int(input("Enter First Number: "))
b = int(input("Enter Second Number: "))
print("a + b = {}".format(a + b))
print("a - b = {}".format(a - b))
print("a * b = {}".format(a * b))
print... |
b7b308edb3291eaf8369e331687b8b85e83e3191 | nickklosterman/PythonStockTracker | /FileOutputHelper.py | 731 | 3.828125 | 4 | def CreateOutputFilename(inputfilename,extension):
"""
Strip out the path and extract the base of the inputfilename for reuse as the base of the outputfilename
I feel like I could have that second argument be a list of things to append dot separated.
"""
filenameWithPath=(inputfilename.split('/'))
... |
264d3c2551cc7d0a4ddfce6b91ba4249220801f4 | UnaiSanchez/python2019 | /recursion/recursion.py | 367 | 3.71875 | 4 | moves =[]
def move(origin, destination):
moves.append([origin,destination])
def hanoi(num_of_disk, origin, temporary, destination):
if num_of_disk == 0:
pass
else:
hanoi(num_of_disk -1,origin,destination,temporary)
move(origin,destination)
hanoi(num_of_disk -1,temporary, orig... |
73f1ce438ebb03c45b3f44740500b6f3dc317020 | ShaotongWen/cs3A | /cs3A_Assignment3.py | 4,968 | 4.125 | 4 | """ Assignment Three: Temperature Conversions - Shaotong Wen """
def print_header():
""" Print the project name and my name. """
print("STEM Center Temperature Project")
print("Shaotong Wen")
def convert_units(celsius_value, units):
""" convert given Celsius temp to Fahrenheit or Kelvin"""
if un... |
475c1e992482bca16a1c82ce2ca9bea454f4f955 | JLCarveth/PyPwGen | /pygen.py | 1,986 | 4.03125 | 4 | from tkinter import *
from random import randint
def generate(num):
# Number of passwords to generate
num = int(num)
# Number of lines in the word file
lc = 2926
for i in range(num):
file = open("words.txt", "r")
r1 = randint(1, lc) # Line number of first... |
dac79a35e7e3db79b67a7f54a1da6a0a3755a5c9 | LEEKYUHO555/MLCourseraPython | /Week1/ex1.py | 1,027 | 3.578125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jul 25 21:29:15 2017
@author: snu13
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import CostComputation as cc
data = np.loadtxt('ex1data1.txt', delimiter=',')
X = data[:,0]
Y = data[:,1]
m = len(Y)
X = np.reshape(X,(m,1))
Y = np.reshape(Y,(m,1... |
ce685b132990f0aa030e816eb344eaee7f820b89 | kiran0794/practicals | /prac 04/list_exercises.py | 718 | 3.921875 | 4 | numbers = []
total = 0
for i in range(0, 5, 1):
number = int(input("Number: "))
numbers.append(number)
total += number
average_number = total/5
print("The first number is ", numbers[0])
print("The second number is ", numbers[4])
print("The smallest number is ", min(numbers))
print("The largest number is "... |
3bfc1a49d738341a5f59052b246232390a607955 | thegautamkumarjaiswal/Algorithm-s_ToolBox_Solutions | /week2_algorithmic_warmup/6_last_digit_of_the_sum_of_fibonacci_numbers/fibonacci_sum_last_digit.py | 1,434 | 3.828125 | 4 | import sys
import unittest
def fibonacci_sum_naive(n):
if n <= 1:
return n
previous = 0
current = 1
sum = 1
for _ in range(n - 1):
previous, current = current, previous + current
sum += current
return sum % 10
def get_fibonacci_last_digit_fast(n):
if n <= 1:
... |
4ab9a00b473fb98303c780df95d149270011953c | marcus-aurelianus/Lintcode-with-Python | /6. Merge Two Sorted Arrays/sol6(naive).py | 490 | 3.703125 | 4 | class Solution:
def mergeSortedArray(self,A,B):
res=[]
while(A and B):
if A[0]<=B[0]:
res.append(A[0])
A.pop(0)
else:
res.append(B[0])
B.pop(0)
while(A):
res.append(A[0])
A.pop(0)
... |
8214f5aadfcd7d8a8ed7ef659ff10bc2366e7dc9 | marcus-aurelianus/Lintcode-with-Python | /66. Binary Tree Preorder Traversal/sol66(recursion).py | 622 | 3.734375 | 4 | class TreeNode:
def __init__(self, val):
self.val = val
self.left, self.right = None, None
class Solution:
"""
@param root: A Tree
@return: Preorder in ArrayList which contains node values.
"""
def preorderTraversal(self, root):
if root==None:
return []
... |
7dd909f4a46030fd6605a9ddf2c986b2cd267c99 | marcus-aurelianus/Lintcode-with-Python | /70. Binary Tree Level Order Traversal II/sol70.py | 933 | 3.65625 | 4 | class TreeNode:
def __init__(self, val):
self.val = val
self.left, self.right = None, None
class Solution:
"""
@param root: A Tree
@return: Level order a list of lists of integer
"""
def levelOrderBottom(self, root):
stk=[]
if root is None:
return s... |
4539a8d87fd33656aaa50919d8ccb47af1dcfa71 | marcus-aurelianus/Lintcode-with-Python | /1. A+B Problem/naive sol.py | 519 | 3.6875 | 4 | def Add(x,y):
INT_RANGE=0xFFFFFFFF
while(y!=0):
x,y=x^y,(x&y)<<1
x&=INT_RANGE
print(x,y)
return x if x>>31 <=0 else x^~INT_RANGE
#test case:
print(0xFFFFFFFF+2)
print(Add(0xFFFFFFFF+1,0xFFFFFFFF+2)) #Failed....
MAX_BIT = 2**32
MAX_BIT_COMPLIMENT = -2**32
def aplusb(a, b):
whil... |
c46991ae5e657c7ea3d19f37e9a6d50798e722e0 | marcus-aurelianus/Lintcode-with-Python | /4. Ugly Number II/sol4.py | 571 | 3.515625 | 4 | class Solution:
"""
@param n: An integer
@return: the nth ugly number as description
"""
def nthUglyNumber(self,n):
last=[0,0,0]
temp=[1,1,1]
mat=[2,3,5]
res=[1]
while len(res)<n:
for i in range(3):
while(res[last[i]]*mat[i])<=res[-... |
4b467fd730041fad33882a1c31038824d35c8d2f | marcus-aurelianus/Lintcode-with-Python | /7. Serialize and Deserialize Binary Tree/sol7(naive).py | 2,260 | 4.0625 | 4 | """
Definition of TreeNode:
"""
class TreeNode:
def __init__(self, val):
self.val = val
self.left, self.right = None, None
class Solution:
"""
@param root: An object of TreeNode, denote the root of the binary tree.
This method will be invoked first, you should design your own algorithm ... |
68024cb72aa6cbef1fc820e95b7c2906dcd20960 | yshshadow/Leetcode | /300-/442.py | 786 | 3.984375 | 4 | # Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.
#
# Find all the elements that appear twice in this array.
#
# Could you do it without extra space and in O(n) runtime?
#
# Example:
# Input:
# [4,3,2,7,8,2,3,1]
#
# Output:
# [2,3]
class Solution(object)... |
c3142b435d27ce7f44222648ca25b6a9742a911a | yshshadow/Leetcode | /300-/819.py | 2,288 | 4.0625 | 4 | # Given
# a
# paragraph and a
# list
# of
# banned
# words,
# return the
# most
# frequent
# word
# that is not in the
# list
# of
# banned
# words.It is guaranteed
# there is at
# least
# one
# word
# that
# isn
# 't banned, and that the answer is unique.
#
# Words in the
# list
# of
# banned
# words
# are
# given in ... |
fb17486a9c96a7424950f43e8a2bbd93ec79082d | yshshadow/Leetcode | /300-/849.py | 1,746 | 4.09375 | 4 | # In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty.
#
# There is at least one empty seat, and at least one person sitting.
#
# Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized.
#
# Return that maximum distan... |
0dfe39b515dc391753d29b540d6af13abefd8269 | yshshadow/Leetcode | /201-250/211.py | 2,515 | 4.1875 | 4 | # Design a data structure that supports the following two operations:
#
# void addWord(word)
# bool search(word)
# search(word) can search a literal word or a regular expression string containing only letters a-z or .. A . means it can represent any one letter.
#
# Example:
#
# addWord("bad")
# addWord("dad")
# addWord... |
705ae02a5d5cc8e6425da01745d8193033926b26 | yshshadow/Leetcode | /300-/689.py | 1,857 | 3.734375 | 4 | # In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum.
#
# Each subarray will be of size k, and we want to maximize the sum of all 3*k entries.
#
# Return the result as a list of indices representing the starting position of each interval (0-indexed). If there are multiple ... |
3b6cc2aa846c67638ece7bcbe29d433c0a73fe12 | yshshadow/Leetcode | /1-50/11.py | 866 | 3.78125 | 4 | # Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
#
# Note: You ma... |
3c81a7fd2beca1666a70b09bfb05c21639068ce8 | yshshadow/Leetcode | /51-100/96.py | 1,153 | 4.03125 | 4 | # Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?
#
# Example:
#
# Input: 3
# Output: 5
# Explanation:
# Given n = 3, there are a total of 5 unique BST's:
#
# 1 3 3 2 1
# \ / / / \ \
# 3 2 1 1 3 2
# ... |
8f7a97f2ffc5476827823f11889506bd337aacfa | yshshadow/Leetcode | /101-150/142.py | 1,013 | 3.90625 | 4 | # Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
#
# Note: Do not modify the linked list.
#
# Follow up:
# Can you solve it without using extra space?
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
se... |
69517ddc62bf4eea00aa98c57d00328813768dc7 | yshshadow/Leetcode | /300-/917.py | 1,056 | 3.8125 | 4 | # Given
# a
# string
# S,
# return the
# "reversed"
# string
# where
# all
# characters
# that
# are
# not a
# letter
# stay in the
# same
# place, and all
# letters
# reverse
# their
# positions.
#
# Example
# 1:
#
# Input: "ab-cd"
# Output: "dc-ba"
# Example
# 2:
#
# Input: "a-bC-dEf-ghIj"
# Output: "j-Ih-gfE-dCba"
#... |
f85d2f42b84cc38349bcb5670e55038f207e465c | yshshadow/Leetcode | /101-150/137.py | 1,195 | 3.8125 | 4 | # Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.
#
# Note:
#
# Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
#
# Example 1:
#
# Input: [2,2,3,2]
# Output: 3
# Example 2:... |
9137c399473cded62f26e36e512433eb4faaa00f | yshshadow/Leetcode | /1-50/48.py | 1,614 | 4.125 | 4 | # You are given an n x n 2D matrix representing an image.
#
# Rotate the image by 90 degrees (clockwise).
#
# Note:
#
# You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
#
# Example 1:
#
# Given input matrix =
# [
#... |
15032af3981c7fd3c82e47902096bc9585c1fa6c | yshshadow/Leetcode | /51-100/65.py | 1,966 | 3.59375 | 4 | # Validate if a given string can be interpreted as a decimal number.
#
# Some examples:
# "0" => true
# " 0.1 " => true
# "abc" => false
# "1 a" => false
# "2e10" => true
# " -90e3 " => true
# " 1e" => false
# "e3" => false
# " 6e-1" => true
# " 99e2.5 " => false
# "53.5e93" => true
# " --6 " => false
# "-+3" => fals... |
285a101641df48d23a6a9ebda6737979b16accdc | yshshadow/Leetcode | /51-100/64.py | 1,110 | 3.859375 | 4 | # Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
#
# Note: You can only move either down or right at any point in time.
#
# Example:
#
# Input:
# [
# [1,3,1],
# [1,5,1],
# [4,2,1]
# ]
# Output: 7
# Explanation: ... |
b99592d95dcd3f2ce168808da0f08c2b5a83da5d | yshshadow/Leetcode | /51-100/94.py | 1,376 | 4.125 | 4 | # Given a binary tree, return the inorder traversal of its nodes' values.
#
# For example:
# Given binary tree [1,null,2,3],
# 1
# \
# 2
# /
# 3
# return [1,3,2].
#
# Note: Recursive solution is trivial, could you do it iteratively?
# Definition for a binary tree node.
class TreeNode(object):
de... |
71a6de0f0a9fe332ddabda301530daa465353f44 | yshshadow/Leetcode | /51-100/79.py | 1,570 | 3.84375 | 4 | # Given a 2D board and a word, find if the word exists in the grid.
#
# The word can 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.
#
# Example:
#
# board =
# [
# ['A','B','C','E']... |
3cc8b1e86eff7ca29a7ee5b1b462223c74e8777d | yshshadow/Leetcode | /101-150/130.py | 1,953 | 3.90625 | 4 | # Given
# a
# 2
# D
# board
# containing
# 'X' and 'O'(the
# letter
# O), capture
# all
# regions
# surrounded
# by
# 'X'.
#
# A
# region is captured
# by
# flipping
# all
# 'O'
# s
# into
# 'X'
# s in that
# surrounded
# region.
#
# Example:
#
# X
# X
# X
# X
# X
# O
# O
# X
# X
# X
# O
# X
# X
# O
# X
# X
# After
# r... |
6c01931c5e7029f7111938e6695cb40c74ea4557 | yshshadow/Leetcode | /151-200/159.py | 1,060 | 3.5625 | 4 | # Given a string s , find the length of the longest substring t that contains at most 2 distinct characters.
#
# Example 1:
#
# Input: "eceba"
# Output: 3
# Explanation: t is "ece" which its length is 3.
# Example 2:
#
# Input: "ccaabbb"
# Output: 5
# Explanation: t is "aabbb" which its length is 5.
import collections... |
c73e65896ce89c0ae540e9330a0214a0a5ba5a93 | yshshadow/Leetcode | /51-100/88.py | 1,074 | 4.21875 | 4 | # Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
#
# Note:
# You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively.
#
class... |
63c123b8011607ac4cf6178567cbed46774a366c | yshshadow/Leetcode | /1-50/34.py | 981 | 3.984375 | 4 | # Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.
#
# Your algorithm's runtime complexity must be in the order of O(log n).
#
# If the target is not found in the array, return [-1, -1].
#
# Example 1:
#
# Input: nums = [5,7,7,8,8,10], target = 8
... |
05a58dd51357f47a523780d27e21a3683e7aca1a | yshshadow/Leetcode | /300-/659.py | 1,356 | 3.859375 | 4 | # You are given an integer array sorted in ascending order (may contain duplicates), you need to split them into several subsequences, where each subsequences consist of at least 3 consecutive integers. Return whether you can make such a split.
#
# Example 1:
# Input: [1,2,3,3,4,5]
# Output: True
# Explanation:
# You c... |
310b99e9b68a2f81323c619977371e3638fc66b1 | yshshadow/Leetcode | /300-/572.py | 1,583 | 4.21875 | 4 | # Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as a subtree of itself.
#
# Example 1:
# Given tree s:
#
# 3
... |
b814f11154e3172734c6a599415b8ff6e1e21292 | yshshadow/Leetcode | /101-150/120.py | 1,378 | 3.796875 | 4 | # Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
#
# For example, given the following triangle
# [
# [2],
# [3,4],
# [6,5,7],
# [4,1,8,3]
# ]
# The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
#
# Note:
... |
e4e0dd857f63821ed317d115ea604a855c335080 | yshshadow/Leetcode | /300-/668.py | 845 | 3.890625 | 4 | # Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1.
#
# For example, with A = "abcd" and B = "cdabcdab".
#
# Return 3, because by repeating A three times (“abcdabcdabcd”), B is a substring of it; and B is not a substring of... |
5a9b0e56fc30dc380875a710ca2be5ef0434551f | yshshadow/Leetcode | /300-/734.py | 1,949 | 4.0625 | 4 | # Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar.
#
# For example, "great acting skills" and "fine drama talent" are similar, if the similar word pairs are pairs = [["great", "fine"], ["acting","drama"], ["skil... |
361c7f5a69c1c303d0c650d867ad4567aa6ccccb | yshshadow/Leetcode | /300-/676.py | 4,374 | 3.984375 | 4 | # Implement a magic directory with buildDict, and search methods.
#
# For the method buildDict, you'll be given a list of non-repetitive words to build a dictionary.
#
# For the method search, you'll be given a word, and judge whether if you modify exactly one character into another character in this word, the modified... |
b1868ddb16d474b647edabf6aa4d8233a6d6fde4 | yshshadow/Leetcode | /101-150/103.py | 1,115 | 4.15625 | 4 | # Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
#
# For example:
# Given binary tree [3,9,20,null,null,15,7],
# 3
# / \
# 9 20
# / \
# 15 7
# return its zigzag level order trav... |
584b822e45b7cb26ccb8e5cacc66cdb8eae399a4 | yshshadow/Leetcode | /251-300/261.py | 1,396 | 4.125 | 4 | # 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.
#
# Example 1:
#
# Input: n = 5, and edges = [[0,1], [0,2], [0,3], [1,4]]
# Output: true
# Example 2:
#
# Input: n = 5, and edges = [[0,1], [1,2], [2,3... |
fb1095935caebcf1355fc3b072cf70e0cf07bb6e | zhanghuandiandian/store | /水杯.py | 1,066 | 3.875 | 4 | '''
水杯:有高度,有容量,有颜色,能盛水
'''
class Pp:
__high = 0
__capacity = 0
__colour = ''
def sethigh(self, high):
if high <= 0:
print('你家水杯没高度!')
else:
self.__high = high
def gethigh(self):
return self.__high
def setcapacity(self, capacity):
if c... |
3c19db040d468a46f65b468fe1cf95c72451766c | phisyche/Python | /recurse_count.py | 233 | 3.890625 | 4 | def countdown(n):
print('Entering countdown(',n,')')
if n == 0:
print('Blastoff!')
else:
print(n)
countdown(n - 1)
print('Exiting from countdown(',n,')')
limit = int(input())
countdown(limit)
|
3992598ae75ac5f8e1b8570701d5bc4d701428e5 | phisyche/Python | /prime.py | 1,213 | 3.96875 | 4 | import math
import random
def finding_prime(number):
num = abs(number)
if num < 4 : return True
for x in range(2, num):
if num % x == 0:
return False
return True
def finding_prime_sqrt(number):
num = abs(number)
if num < 4 : return True
for x in range(2, int(math.sqrt(n... |
75c5f48b2172f10b30c255377d81b00ee326c0d4 | Adolfoderueda/MBDO2-8 | /PocketCalculator/calculator_1.0_beta.py | 2,772 | 3.859375 | 4 | import re
inp_string = '11+2+3*4'
math_regex = '^[0-9\/\*\+\-\s\.]+$'
digit_regex = '([0-9\.]+?)'
operator_regex = '([\*\/\+\-])'
one_operator_regex = '.*([\+\-\*\/]).*'
two_operators_regex = '.*([\+\-\*\/][\+\-\*\/]).*'
def get_tokenized_math_expression(inp_string):
inp_match = re.match(math_regex, inp_string)
... |
ff9787f9f290b848b5ff7fda40e31b852ed412ad | TechSajal/Hacktoberfest-2020-Baby | /card.py | 1,269 | 3.609375 | 4 | def luhn(card_number):
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(card_number)
print(digits)
odd_digits = digits[-1::-2]
print(odd_digits)
even_digits = digits[-2::-2]
print(even_digits)
checksum = 0
checksum += sum(odd_digits)
print(checksum)
... |
ebcb25a475c90515ca94f8e876cf5e320b7854dd | TechSajal/Hacktoberfest-2020-Baby | /creating and blocking password.py | 504 | 3.796875 | 4 | our_password = "pass1234"
your_answer = ""
number_of_try = 0
max_number_of_try = 4
Max_try = "not reached"
while your_answer != our_answer and Max_try != "Reached":
if number_of_try < max_number_of_try:
your_answer = input("what is the password")
number_of_try = number_of_try + 1
def is_positive(number):
... |
eae4d6869a5da8313f21d21a5e2187f809e95b9c | pujajha1/leetcode | /removeElement.py | 221 | 3.625 | 4 | #https://leetcode.com/problems/remove-element/submissions/
class Solution:
def removeElement(self, nums: 'List[int]', val: 'int') -> 'int':
while val in nums:
nums.remove(val)
print(nums)
|
bcc6aaa7af77ae8cd4352a91e809802aa4ff43df | pujajha1/leetcode | /lengthOfLastWord.py | 196 | 3.78125 | 4 | #https://leetcode.com/problems/length-of-last-word/
class Solution:
def lengthOfLastWord(self, s: str) -> int:
splitted_word=s.strip().split(" ")
return len(splitted_word[-1])
|
c90809b4a77fffeb5dc56c2cd50408fb724c7f62 | pujajha1/leetcode | /findNumbersWithEvenNumbersDigits.py | 294 | 3.65625 | 4 | #https://leetcode.com/problems/find-numbers-with-even-number-of-digits/
class Solution:
def findNumbers(self, nums: List[int]) -> int:
counter=0
for i in nums:
if(len(str(i)) % 2==0):
counter=counter+1
continue
return counter
|
4a8b40423d722376442853dcf432880e736e7247 | loafaway/Lesson0 | /tower-hanoi-6a.py | 6,691 | 3.765625 | 4 | ############################################################
#
# Title: The Tower of Hanoi of 6 Levels
# Author: Greg Huang
# Date: 2019/03/27
# Copyright: Released under a "Simplified BSD" license
#
############################################################
import pygame
#######################... |
56d516e70dc4e8fd1727107e763d67df0e660ef2 | ericlegoaec/NLP_Kickstarter | /removestopwords.py | 1,560 | 3.5 | 4 | import nltk
import re
from nltk.corpus import stopwords
set(stopwords.words('english'))
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.stem import PorterStemmer
from nltk.tokenize import sent_tokenize, word_tokenize
def process(example_sent):
#example_sent = "This is a sample s... |
caefacfb01f2294faaca06771c950d475b7c4913 | syedsardar/test | /2.py | 784 | 3.78125 | 4 | '''
Read the CSV file as an input argument (or take from user) to your program. Convert the csv and write in parquet (it is just another format). You can use any library. Test with https://support.staffbase.com/hc/en-us/article_attachments/360009197011/username-password-recovery-code.csv
IMPORTANT NOTEs:
1. This work... |
02c30508f7679af76ba54873ea96ebd6c61f64a0 | jamiezeminzhang/Leetcode_Python | /array/349_Intersection_of_two_arrays.py | 618 | 3.890625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu May 19 21:17:47 2016
349. Intersection of Two Arrays
Total Accepted: 3637 Total Submissions: 7872 Difficulty: Easy
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].
Note:
Each element in the ... |
01907a3b9726f027261677c43991d1d1f8925f82 | jamiezeminzhang/Leetcode_Python | /array/209_O_Minimum_Size_Subarray_Sum.py | 2,587 | 3.546875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Feb 18 06:37:48 2016
209. Minimum Size Subarray Sum
Total Accepted: 31399 Total Submissions: 120310 Difficulty: Medium
Given an array of n positive integers and a positive integer s, find the minimal length of a
subarray of which the sum ≥ s. If there isn't one, return 0 i... |
c802f52058a7ee22e3e81d09dda3649af896832a | jamiezeminzhang/Leetcode_Python | /ALL_SOLUTIONS/002_OO_add_two_numbers.py | 1,223 | 3.5625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 14:15:25 2015
LeetCode #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... |
45657a607fe1e0302b487d176efba6a592f3708a | jamiezeminzhang/Leetcode_Python | /tree/236_O_Lowest_Common_Ancestor_of_a_Binary_Tree.py | 1,491 | 3.546875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Feb 20 14:09:54 2016
236. Lowest Common Ancestor of a Binary Tree
Total Accepted: 33643 Total Submissions: 117820 Difficulty: Medium
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
According to the definition of LCA on Wikipedia: ... |
5ac9459e51c352816fcd67ff210241423cfd96b3 | jamiezeminzhang/Leetcode_Python | /ALL_SOLUTIONS/166_OO_Fraction_to_Recurring_Decimal.py | 1,610 | 3.78125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sun Feb 14 08:42:10 2016
166. Fraction to Recurring Decimal
Total Accepted: 26284 Total Submissions: 180852 Difficulty: Medium
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.
If the fractional part is repeatin... |
1824146d87b193ac59abc7d31570cb49aeb56751 | jamiezeminzhang/Leetcode_Python | /ALL_SOLUTIONS/016_3sum_closest.py | 1,185 | 3.640625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Jul 23 11:06:39 2015
LeetCode # 16 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum
is closest to a given number, target. Return the sum of the three integers.
You may assume that each input would have exactly one solution.
For e... |
d6f23222d4089c8cbe206f88549bbe82045cffb0 | jamiezeminzhang/Leetcode_Python | /recursion/200_Number_of_Islands.py | 1,339 | 3.9375 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Feb 15 07:53:24 2016
200. Number of Islands
Total Accepted: 35558 Total Submissions: 133900 Difficulty: Medium
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands.
An island is surrounded by water and is formed by connecting adjacent lands hori... |
ee7a31838dbba2216f509bfd2a764b6d825cbe4a | jamiezeminzhang/Leetcode_Python | /_Google/282_OO_Expression_Add_Operators.py | 1,717 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Mon Feb 22 10:57:57 2016
282. Expression Add Operators
Total Accepted: 7924 Total Submissions: 33827 Difficulty: Hard
Given a string that contains only digits 0-9 and a target value, return all possibilities
to add binary operators (not unary) +, -, or * between the digits so ... |
4d11a670a681f959935ec2f5b147b038479a68b7 | jamiezeminzhang/Leetcode_Python | /math/263_Ugly_Number.py | 739 | 3.90625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sun Feb 21 11:50:57 2016
263. Ugly Number
Total Accepted: 42870 Total Submissions: 119930 Difficulty: Easy
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example,
6, 8 are ugly... |
52a5ba4c48f84ef742977ed01847aa088a71eab1 | jamiezeminzhang/Leetcode_Python | /ALL_SOLUTIONS/082_OO_Remove_Duplicates_from_Sorted_List_II.py | 1,133 | 3.65625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Jan 30 00:07:23 2016
82. Remove Duplicates from Sorted List II
Total Accepted: 63733 Total Submissions: 243150 Difficulty: Medium
Given a sorted linked list, delete all nodes that have duplicate numbers,
leaving only distinct numbers from the original list.
For example,
G... |
2df3c162dc8e6e03f03765467e69d4f7611abd73 | jamiezeminzhang/Leetcode_Python | /ALL_SOLUTIONS/133_OO_Clone_Graph.py | 2,324 | 3.921875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Fri Feb 5 10:39:32 2016
133. Clone Graph
Total Accepted: 58728 Total Submissions: 238122 Difficulty: Medium
Clone an undirected graph. Each node in the graph contains a label and a list
of its neighbors.
OJ's undirected graph serialization:
Nodes are labeled uniquely.
We u... |
8afdc9e14d3d5eeb39515d7c7c37dc7c6314f326 | jamiezeminzhang/Leetcode_Python | /string/214_OO_Shortest_Palindrome.py | 1,510 | 3.734375 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Feb 18 14:37:40 2016
214. Shortest Palindrome My Submissions Question
Total Accepted: 16240 Total Submissions: 85929 Difficulty: Hard
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it.
Find and return the shortest palindrome... |
c7606cc56a4fd5d4ebfaf334fc83d14abb76e56d | jamiezeminzhang/Leetcode_Python | /hash/049_Group_Anagrams.py | 982 | 4.03125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Jan 16 20:31:38 2016
49. Group Anagrams
Total Accepted: 76769 Total Submissions: 275417 Difficulty: Medium
Given an array of strings, group anagrams together.
For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"],
Return:
[
["ate", "eat","tea"],
["nat","tan"... |
af56b726456d09090c7fe1ef305693cb46f8de46 | jamiezeminzhang/Leetcode_Python | /_Google/017_letter_combinations_of_a_phone_number.py | 1,966 | 3.890625 | 4 | # -*- coding: utf-8 -*-
"""
Created on Thu Jul 23 12:25:52 2015
LeetCode #17 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
class Solution(object):... |
67d203cad666d57af4423c610acff5d55648a806 | jamiezeminzhang/Leetcode_Python | /string/006_zigzag_conversion.py | 1,166 | 3.6875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jul 21 12:02:32 2015
LeetCode #6: ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this:
(you may want to display this pattern in a fixed font for better legibility)
P A H N
A P L S I I G
Y I R
And the... |
a5ce83c5625f2614300b5582a8d72b4c99f87539 | jamiezeminzhang/Leetcode_Python | /_Google/128_OO_Longest_Consecutive_Sequence.py | 1,660 | 3.75 | 4 | # -*- coding: utf-8 -*-
"""
Created on Fri Feb 5 01:03:59 2016
128. Longest Consecutive Sequence My Submissions Question
Total Accepted: 58261 Total Submissions: 186354 Difficulty: Hard
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
For example,
Given [100, 4, 200,... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.