blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
3.06M
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
3.06M
306ef53cead7e4e63689b30143d55d73dda213b1
Harshita1503/LEET-CODE
/May 12 Single element in a sorted array.py
571
3.671875
4
'''You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.''' class Solution: def singleNonDuplicate(self, nums: List[int]) -> int: l, r = 0, len(nums) - 1 ...
1d02022f31baf827e345e86ed9765736d4500e59
rkumar75681/Python-Tutorial
/6. Chapter 6/08_pr_04.py
232
4.09375
4
username = input("Enter User Name: \n") # count = (len(username)) # print(" UserName = ", username) # print(" count UserName = ", count) # if count > 10: # print(" UserName is > 10") # else: # print(" UserName is < 10")
48b4a7b500a60ed7edbd8b0951f51f10c0b18732
rafacharlie/POO2
/python/ej2/PruebaVehiculos.py
1,573
3.609375
4
''' Prueba de la clase vehiculos @author: Rafael Infante ''' from programasPoo.Bicicleta import Bicicleta from programasPoo.Coche import Coche ''' Funcion vacia que muestra un menu ''' def mostrarMenu(): print("\t\tMENU") print("\t\t====\n") print("1. Anda con la bicicleta") print("2. Haz el ...
65d55852750cc5585ea7251accf88c72c68fc3ff
Acedalus/assignment3
/act3.py
1,735
4.03125
4
print("ISQA 3900 Lumber Price Calculator") answer = "y" while answer == "y": print("Please input how much feet of board and of what board type you want (common or rare)") #print("Enter number of board feet: ") #while True: quantity = int(input("Enter amount of board feet desired: ")) if quantity > 0: ...
c0c3e6c6059d2253dd069e75804e4250fc1fe3c1
sloevhaug/TDT4136
/oving3/algorithms.py
4,033
3.875
4
import bisect from Node import Node ''' For all algorithms: start: start node target: target node nodes: array of all nodes openSet: the OPEN list closedSet: the CLOSED list ''' def astar(start, target, nodes, openSet, closedSet): '''Setting the H-value of the start node using manhattan distance.''' start.H =...
53387bf3d5add5a226a7993807565c388965488f
ronaldoafonso/programming
/algorithms/gcd/gcd2.py
194
3.78125
4
# Uses python3 def gcd(a, b): if b == 0: return a aprime = a % b return gcd(b, aprime) s = input() a = int(s.split(' ')[0]) b = int(s.split(' ')[1]) d = gcd(a, b) print(d)
4daa3cf70e5b150ee86291279540409b7ba40b83
CowSai4/Python_CSP_Files
/turtle/1.1/r_p_s.py
3,474
4.03125
4
import random print('Welcome to rock, paper, and scissors') print('Your answer must have the first letter be uppercase') player_choice = input('Rock, Paper, or Scissors?') computer_choice = random.choice(['Rock','Paper','Scissors']) if player_choice == 'Rock' and computer_choice == 'Paper': print("You lost!") ...
0beb82cd116c6f550fcb3d0de1b553b7ec75db28
CowSai4/Python_CSP_Files
/turtle/1.2/stopwatch.py
1,195
3.53125
4
import turtle, time screen = turtle.Screen() time = 0 trtle = turtle.Turtle() start = turtle.Turtle('circle') start.color('Green') start.shapesize(2) stop = turtle.Turtle('circle') stop.color('yellow') stop.shapesize(2) stop.penup() stop.goto(100,0) stop.pendown() reset = turtle.Turtle('circle') reset.color('red'...
264f8975637a2b7bf595fe574a824fc3ef1d3efd
HolgerKunz/machine_learning_cca1
/Module0.py
27,527
4.28125
4
# coding: utf-8 ## Module 0: Overview of machine learning practice ### Goals of this tutorial # - Introduce the basics of Machine Learning, and some skills useful in practice. # - Introduce the syntax of scikit-learn, so that you can make use of the rich toolset available. # ## Learning activity 1: Introduction to...
eac534e904306809a5c699e6ec17e7829f41ecc2
artkpv/code-dojo
/yandex.ru/Algorithm2018/round2/pra.py
282
3.625
4
#!python3 def swap(a, i, j): t = s[i] s[i] = s[j] s[j] = t s = input().strip() n = len(s) a = [] for i in range(n): for j in range(i+1, n): if s[j] == s[i]: continue # swap and check it swap(a, i, j)
1663ce318950835dc5be971ee168c840c0d632e8
artkpv/code-dojo
/leetcode.com/problems/longest-common-prefix/pr.py
668
3.59375
4
#!python3 class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if not strs: return "" if len(strs) == 1: return strs[0] i = 0 while True: are_same = True # check that all are the same at i-th for j in range...
99d5e2b9ca77e7603c3246cd7c7893e8f9c865f5
artkpv/code-dojo
/_other/insert_and_print_db/pr.py
2,747
3.921875
4
''' Given array of operations: INSERT item price VIEW - - where item - lowercase english chars price - 1..10**5 INSERT is to insert into a DB item with price. VIEW is to print k-th item in asc order by (price, item). k is the number of VIEW command. Example: INSERT orange 1 INSERT apple 1 VIEW - - > apple VIEW - -...
3f474127d25808d08bf770c930b3c10ad7ce859b
artkpv/code-dojo
/codeforces.com/contest/1266/a/pr.py
747
3.515625
4
#!python3 """ w1ld [dog] inbox dot ru """ from collections import deque, Counter import array from itertools import combinations, permutations from math import sqrt import unittest def read_int(): return int(input().strip()) def read_int_array(): return [int(i) for i in input().strip().split(' ')] #######...
5ae6c9d810d612fe33d28e0fc0baef5d4ebe2bd8
artkpv/code-dojo
/hackerrank.com/challenges/counting-valleys/counting-valleys.py
216
3.734375
4
#!python3 n = int(input().strip()) steps = input().strip() altitude = 0 valleys = 0 for s in steps: if s == 'D' and altitude == 0: valleys += 1 altitude += (1 if s == 'U' else -1) print(valleys)
e10f0a220c1aa4cd72167639e916b3507447ac8d
artkpv/code-dojo
/_other/has_vertical_line.py
1,604
4.0625
4
#!python3 """ Given (x,y) points determine whether there is a vertical line that separates them all into to symmetrical groups where x1,y1 at left has x2,y2 at right for all points at left. """ import unittest from collections import defaultdict def hasline(points): if not points: return False point...
86a77a24b09b8d819667e8d15e54b825aae85635
artkpv/code-dojo
/hackerrank.com/challenges/maximizing-xor/maximizing-xor.py
253
3.78125
4
#!python3 def maxXor(l, r): max_ = 0 for i in range(l, r+1): for j in range(i+1, r+1): if max_ < i^j: max_ = i^j return max_ if __name__ == '__main__': l = int(input()) r = int(input()) print(maxXor(l, r))
37cfe71904a96d23ac6d9283692ae8839e782045
artkpv/code-dojo
/codeforces.com/contest/231/a/pr.py
464
3.515625
4
#!python3 from collections import deque, Counter import array from itertools import combinations, permutations from math import sqrt import unittest def read_int(): return int(input().strip()) def read_int_array(): return [int(i) for i in input().strip().split(' ')] #######################################...
81966c0d86f93d1f53c3813667dc6d69f5be73b9
artkpv/code-dojo
/hackerrank.com/challenges/sherlock-and-anagrams/problem.py
695
3.75
4
#!python3 """ https://www.hackerrank.com/challenges/sherlock-and-anagrams Anagram - rearranged letters ss - consequentive letters from s 1 <= |ss| < n s: 2..100 q: 1..10 Anagrams - ? 1) BF. For 1..n-1, all ss, count all pairs. anagrams = pairs*(pairs-1)/2. T: O(n^3*q), ~10^7. S: O(n^2) """ qu...
d47c6b6fef12ae6308c1d456ab7f89798e84277b
artkpv/code-dojo
/codeforces.com/contest/236/a.py
121
3.578125
4
#!python3 l = len(set(c for c in input().strip() if c != ' ')) print('CHAT WITH HER!' if l % 2 == 0 else 'IGNORE HIM!')
b88409bd815106b517f1e4b00a10167110d45443
artkpv/code-dojo
/hackerrank.com/contests/101hack51/fair-cake-cutting/fair-cake-cutting.py
113
3.5
4
#!/bin/python3 import math A,B,a = [int(i) for i in input().strip().split(' ')] print(math.floor(a*B/A))
e1cebb914bbd921fb6422dea34085c3486cd48c2
artkpv/code-dojo
/projecteuler.net/61/problem61.py
5,368
3.640625
4
""" https://projecteuler.net/problem=61 Cyclical figurate numbers Problem 61 Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae: Triangle P3,n=n(n+1)/2 1, 3, 6, 10, 15, ... Square P4,n=n2 1, 4, 9, 16...
a10b53293b42d3946ccd14a05505706c6fac5e55
artkpv/code-dojo
/codeforces.com/contest/1107/a.py
246
3.578125
4
#!python3 for query in range(int(input().strip())): n = int(input().strip()) s = input().strip() if int(s[0]) >= int(s[1:]): print("NO") else: print("YES") print("2") print(s[0], s[1:])
1f5536100003b899c3df5c18583910b0b615c8d7
artkpv/code-dojo
/leetcode.com/house-robber-iii/pr.py
1,590
3.796875
4
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None """ I1 BF Preorder, each can be 0 or 1. Thus O(2^n) I2 Cache optimal for a tree if root 0 or 1. optimal[(v,0)] - optimal if v not taken optimal[(v,1)] - opt...
0eb734a25445170586ce9668c7b74cb717f4882f
artkpv/code-dojo
/_other/almost_palindrom.py
861
3.78125
4
#!python3 import unittest def isap(s): if not s: return True def ispalindrom(lo, hi): l = hi - lo + 1 if l <= 1: return True for i in range(l//2): if s[lo+i] != s[hi-i]: return False return True for i in range(len(s)//2): ...
95e1261174ddc52eda1288c2906bc28f2485cfef
vogtalex/LeapYear
/Alex_Vogt_hw1.py
313
4.0625
4
print('\nWelcome to HW1!') num = int(input("Enter a year: ")) leapYear = 0 if (num % 4) == 0: leapYear = 1 if (num % 100) == 0: leapYear = 0 if (num % 400) == 0: leapYear = 1 if (leapYear == 0): print(num, "is not a leap year.\n") if (leapYear == 1): print(num, "is a leap year.\n")
cfad58f3dc4cfd15dfeb4e08bc3be218cffe6dbf
RussellJBrown/MonopolySimulation
/monop.py
4,247
4.03125
4
import random from turtle_mon import turtles #In Jail def gotojail(count,board,total): temp_count = 1 while temp_count == 3: dice1 = random.randint(1,6) dice2 = random.randint(1,6) temp_total = dice1 + dice2 total = 11 if dice1 == dice2: count += 1 total = total+temp_total return co...
d987849f3095d826a9eb075f4bd24b363ac72f3c
tomn46037/rpiWSi
/rpiWSi/ws_thread_worker.py
1,880
3.671875
4
import threading,time class ThreadWorker(): ''' The basic idea is given a function create an object. The object can then run the function in a thread. It provides a wrapper to start it,check its status,and get data out the function. ''' def __init__(self,func,func_on_finished=None): sel...
5ccbfe65afb73421348d409ba7a1d5ff33502dbf
Uncccle/StudentMangementSystem
/mangersystem.py
2,562
3.765625
4
from student import * class StudentManager(object): def __init__(self): #存储学员的列表 self.student_list=[] def run(self): # 1. 加载文件里面的学员数据 while 1: self.show_menu() # 2. 显示功能菜单 # 3. 用户输入目标功能序号 menu_num=int(input(...
b54c39fcb18dfd632290cd7498e146481ac4f7d5
PengNi/dsim_module
/similarity_go.py
2,889
3.640625
4
#! /usr/bin/env python3 """calculate similarity of gene or disease pairs based on GO""" import time def diseases_similarity_go(diseases, disease2gene, gene2go, go2gene): """ calculate simialrity of disease pairs based on GO. :param diseases: :param disease2gene: :param gene2go: :param go2gene:...
13f01bd4046cc95a989b96d5df9ae515a74cac7a
roctubre/data-structures-algorithms
/algorithmic-toolbox/week4_divide_and_conquer/points_and_segments.py
1,981
3.828125
4
# Uses python3 import sys import random def randomized_quick_sort(a, l, r): if l >= r: return k = random.randint(l, r) a[l], a[k] = a[k], a[l] #use partition3 m1, m2 = partition3(a, l, r) randomized_quick_sort(a, l, m1); randomized_quick_sort(a, m2 + 1, r); def partition3(a, l, r): #write your code here...
fd308dfe79f17d1ba02a8a3db611c084267d02f9
roctubre/data-structures-algorithms
/algorithmic-toolbox/week6_dynamic_programming2/knapsack.py
625
3.515625
4
# Uses python3 import sys import numpy as np def optimal_weight(W_max, weights): value = np.zeros((len(weights)+1, W_max+1)) for item in range(1, len(weights)+1): for w in range(1, W_max+1): value[item, w] = value[item-1, w] if weights[item-1] <= w: val = value[i...
8b1b3a11b0a59b3a12df661cd6ef582ae0ab6a27
roctubre/data-structures-algorithms
/algorithmic-toolbox/week3_greedy_algorithms/largest_number.py
1,269
3.78125
4
#Uses python3 import sys import math def largest_number(a): res = "" l = a.copy() while len(l) != 0: maxDigit = -math.inf for digit in l: if isGreaterOrEqual(digit, maxDigit): maxDigit = digit res += str(maxDigit) l.remove(maxDigit) ...
1a2b3e1a472bdb2ed859495d78225982cfc81191
lidongdongbuaa/leetcode2.0
/图/无向图/判断孤立和分群/1202. Smallest String With Swaps.py
4,067
4.40625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/11 17:04 # @Author : LI Dongdong # @FileName: 1202. Smallest String With Swaps.py '''''' ''' 题目分析 1.要求:You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. ...
64da48fd4e3e968fb5433bc32946bba9dfefdb60
lidongdongbuaa/leetcode2.0
/链表/链表的归并与添加/708. Insert into a Cyclic Sorted List.py
8,491
4.21875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2019/11/20 8:49 # @Author : LI Dongdong # @FileName: 708. Insert into a Cyclic Sorted List.py '' ''' 题目分析 1.要求:Given a node from a cyclic linked list which is sorted in ascending order, write a function to insert a value into the list such that it remains a ...
44f4719412b80f7f98e7009a329842443483f3b8
lidongdongbuaa/leetcode2.0
/回溯法/78. Subsets.py
1,194
3.859375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/30 21:31 # @Author : LI Dongdong # @FileName: 78. Subsets.py '''''' ''' 题目概述:求一个序列的所有子集 题目考点: 解决方案: 方法及方法分析: time complexity order: space complexity order: 如何考 ''' ''' A. math idea 数学归纳法 Time:O(2^n * n), product 2^n subset, add to res O(N) Space:O(2^n *...
8366aec591eec5485b24445045f0739e6f79db84
lidongdongbuaa/leetcode2.0
/双指针/对撞对开指针/11. Container With Most Water.py
1,753
3.796875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/4/16 15:24 # @Author : LI Dongdong # @FileName: 11. Container With Most Water.py '''''' ''' 题目概述:求不同边长容器的最大盛水量 题目考点:two pointer的两边到中间的递进方法 解决方案: 不断移动短边到中间,更新盛水量 方法及方法分析: time complexity order: O(n) space complexity order: O(1) 如何考 ''' ''' input: nums, li...
bcec131958b133e8b0590e9f0827c7956e7ea33e
lidongdongbuaa/leetcode2.0
/回溯法/求点到点的所有路径.py
2,293
3.71875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/30 11:00 # @Author : LI Dongdong # @FileName: 求点到点的所有路径.py '''''' ''' 题目概述:给定一个矩阵,求两点之间的所有路径 题目考点:求所有路径必须用dfs(回溯法),用visite的保证不往回走 解决方案: 方法及方法分析: time complexity order: space complexity order: ''' ''' 矩阵 求矩阵一个角到另一个角的所有路径 A.backtrack - template 1 易错点, x是小...
f9d07c3b4fbdc162b266613270fb975eac8e097d
lidongdongbuaa/leetcode2.0
/位运算/汉明距离/461. Hamming Distance.py
1,551
4.28125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/1/16 20:33 # @Author : LI Dongdong # @FileName: 461. Hamming Distance.py '''''' ''' 题目分析 1.要求:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Input: x = 1, y = 4 Output: 2 Explanation: 1 (...
e88f7472da1d78f89cd3a23e98c97c3bc054fba7
lidongdongbuaa/leetcode2.0
/二叉树/二叉树的遍历/DFS/145. Binary Tree Postorder Traversal.py
1,978
4.15625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/2/19 20:15 # @Author : LI Dongdong # @FileName: 145. Binary Tree Postorder Traversal.py '''''' ''' 题目分析 1.要求: Given a binary tree, return the postorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ ...
46b81dfff7d6bdc9367e7c3a6ee1bb9a7b925c37
lidongdongbuaa/leetcode2.0
/链表/链表排序与划分/143. Reorder List.py
4,382
4.09375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2019/11/13 7:01 # @Author : LI Dongdong # @FileName: 143. Reorder List.py '''''' ''' 题目分析 1.要求:Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You may not modify the values in the list's nodes, only nodes itself may b...
853b92d435912f16fbcedbfde5e72d6fc1f48bbf
lidongdongbuaa/leetcode2.0
/图/有向图/路径-求层数/444. Sequence Reconstruction.py
6,443
3.921875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/4 19:30 # @Author : LI Dongdong # @FileName: 444. Sequence Reconstruction.py '''''' ''' 题目分析 1.要求:Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. The org sequence is a permutation of the integers from 1 to ...
7b2ffd07955b5c356405909fc2649e6f88a5542d
lidongdongbuaa/leetcode2.0
/位运算/数学相关问题/201. Bitwise AND of Numbers Range.py
1,796
4.15625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/1/18 9:39 # @Author : LI Dongdong # @FileName: 201. Bitwise AND of Numbers Range.py '''''' ''' 题目分析 1.要求:Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. Example 1: Input: [5,7] Output:...
8a4ccf34efe6041af0f3d69dae882df49b30d0e8
lidongdongbuaa/leetcode2.0
/二分搜索/有明确的target/33. Search in Rotated Sorted Array.py
2,283
4.21875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/12 15:24 # @Author : LI Dongdong # @FileName: 33. Search in Rotated Sorted 数组.py '''''' ''' 题目分析 - 本题重点看 find the target value in the sorted rotated array, return its index, else return -1 O(logN) binary search problem input: nums:list[int], repeated valu...
01aeba94e37e74be60c0b9232b80b18edcdf251e
lidongdongbuaa/leetcode2.0
/二叉树/路径和/257. Binary Tree Paths.py
2,842
4.1875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/2/26 16:16 # @Author : LI Dongdong # @FileName: 257. Binary Tree Paths.py '''''' ''' 题目分析 1.要求:Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example: Input: 1 / \ 2 ...
7fab504e2bf2fbdf95ba142fb630b38fb34b4ab4
lidongdongbuaa/leetcode2.0
/二分搜索/有明确的target/367. Valid Perfect Square.py
2,926
4.34375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/12 11:19 # @Author : LI Dongdong # @FileName: 367. Valid Perfect Square.py '''''' ''' 题目分析 1.要求:Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function suc...
31f08aa56d0d69151f39a7928b1bc0c9c5432c31
lidongdongbuaa/leetcode2.0
/数据结构与算法基础/leetcode周赛/200329/Count Number of Teams.py
2,737
3.9375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/29 12:21 # @Author : LI Dongdong # @FileName: Count Number of Teams.py '''''' ''' 题目概述: 题目考点: 解决方案: 方法及方法分析: time complexity order: space complexity order: 如何考 ''' ''' from head to end, choose arr which is ascedning or descending with 3 elem, soldier are...
656d6352c80b070e9760832e961a7c3443ed5c94
lidongdongbuaa/leetcode2.0
/二分搜索/有明确的target/81. Search in Rotated Sorted Array II.py
2,724
4.1875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/17 11:18 # @Author : LI Dongdong # @FileName: 81. Search in Rotated Sorted 数组 II.py '''''' ''' 题目概述:在rotated sorted array里面找目标值 题目考点: 在分块后,块可能不是sorted的,出现头值l和尾值mid重复,怎么处理 解决方案: 不断缩进left part的left边界,直到l不等于mid,此时left块是sorted,再进行binary search 方法及方法分析:brute fo...
75f1b14b0446160b33f49083a1e5ce7dabe5f6d7
lidongdongbuaa/leetcode2.0
/链表/链表删除/83. Remove Duplicates from Sorted List.py
3,424
4.125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2019/11/4 22:35 # @Author : LI Dongdong # @FileName: 83. Remove Duplicates from Sorted List.py '''''' ''' 83. Remove Duplicates from Sorted List.py 题目分析 1.要求:Given a sorted linked list, delete all duplicates such that each element appear only once. 2.理解:删除排序链表的重复...
bc11ccb0e884992c3a8ef01eef49fe701ae3ea78
lidongdongbuaa/leetcode2.0
/二叉树/二叉树的性质/111. Minimum Depth of Binary Tree.py
3,076
4.125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/2/12 13:55 # @Author : LI Dongdong # @FileName: 111. Minimum Depth of Binary Tree.py '''''' ''' 题目概述:求树的最小深度,以leaf为最底端 题目考点:分治 dfs ; bfs 解决方案:求所有的深度,返回最小的 dfs ; 直接求返回最小值;bfs返回第一个leaf的深度 方法及方法分析: time complexity order: O(n) space complexity order: dfs:O(logN)...
b20e9404095fe9b959a709747ef4685a3ac5798a
lidongdongbuaa/leetcode2.0
/二分搜索/没有明确的target/458. Last Position of Target (Lintcode).py
1,173
4.21875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/12 18:52 # @Author : LI Dongdong # @FileName: 458. Last Position of Target (Lintcode).py '''''' ''' 题目分析 Description Find the last position of a target number in a sorted array. Return -1 if target does not exist. Example Given [1, 2, 2,...
8148d782b15bb23cf7cf33e1cc359f6c84d3d9f4
lidongdongbuaa/leetcode2.0
/数据结构与算法基础/leetcode周赛/200105/5303. Decrypt String from Alphabet to Integer Mapping.py
1,225
3.65625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/1/5 11:43 # @Author : LI Dongdong # @FileName: 5303. Decrypt String from Alphabet to Integer Mapping.py '''''' ''' split 分拆法 ''' class Solution: def freqAlphabets(self, s: str) -> str: dic = {} for i in range(1, 27): dic[i] =...
58fdea6d3b41f135b51a9da3bea9013ebaaaced7
lidongdongbuaa/leetcode2.0
/数据结构与算法基础/leetcode周赛/200315/Lucky Numbers in a Matrix.py
1,410
3.78125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/15 11:49 # @Author : LI Dongdong # @FileName: Lucky Numbers in a Matrix.py '''''' ''' 题目目的概述 方法及方法分析: time complexity order: space complexity order: 如何考 ''' ''' find the value which is min in row and max in column input:matrix[[int,int]]; len(matrix) ra...
fc476192c47742817563e08dd00494d6bb4d0cae
lidongdongbuaa/leetcode2.0
/数据结构与算法基础/leetcode周赛/200216/Product of the Last K Numbers.py
3,550
4.34375
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/2/16 11:58 # @Author : LI Dongdong # @FileName: Product of the Last K Numbers.py '''''' ''' 题目分析 1.要求: Implement the class ProductOfNumbers that supports two methods: 1. add(int num) Adds the number num to the back of the current list o...
0b95f658522d37127d2e7912bfc50cf7999d7054
lidongdongbuaa/leetcode2.0
/贪心算法/区间问题/452. Minimum Number of Arrows to Burst Balloons.py
1,499
3.625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/4/10 20:28 # @Author : LI Dongdong # @FileName: 452. Minimum Number of Arrows to Burst Balloons.py '''''' ''' 题目概述:重叠区间射箭,问最少几箭,全部射完 题目考点:重叠区间,问最多几个不重叠的区间 解决方案:Greedy + sort 方法及方法分析: time complexity order: O(nlogn) space complexity order: O(1) 如何考 ''' ''' in...
f2854fd227e6dac37a19f0b1da696a09b9540740
lidongdongbuaa/leetcode2.0
/链表/链表的归并与添加/708. 自拟题.py
3,742
3.890625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2019/11/22 9:57 # @Author : LI Dongdong # @FileName: 708. 自拟题.py '''''' ''' 自拟题1 1.要求:在sorted single linklist 插入node,keep linklist sorted 2.理解:在单链表中插入node 3.类型:链表插入 4.方法及方法分析: time complexity order: space complexity order: 5.edge case: for linklist, it is ...
d6720a50421f4d5f3c9e73118310b2ab65821dc7
lidongdongbuaa/leetcode2.0
/动态规划/股票问题/188. Best Time to Buy and Sell Stock IV.py
2,027
3.921875
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/4/10 11:54 # @Author : LI Dongdong # @FileName: 188. Best Time to Buy and Sell Stock IV.py '''''' ''' 题目概述:买卖最多k次 题目考点: 解决方案: 方法及方法分析: time complexity order: space complexity order: 如何考 ''' ''' A. k is a large number 易错点: k很大,故k > n //2时,就相当于没有约束,此时递归不...
a071f8a8e7a5864c6c39bea8ef59fa6c5b329c3c
lidongdongbuaa/leetcode2.0
/链表/链表的归并与添加/23. Merge k Sorted Lists.py
9,049
4.125
4
# -*- coding: utf-8 -*- # @Time : 2019/10/17 17:09 # @Author : LI Dongdong # @FileName: 23. Merge k Sorted Lists.py '' ''' 题目分析 1.要求:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 2.理解: 合并多个链表 3.类型:链表题,合并链表 4.方法:list储存重构法;迭代法两两合并;递归法两两合并;一一合并;优先队列/堆 time complexi...
7dee9c17028660da0486ce14856cd129c080fd97
lidongdongbuaa/leetcode2.0
/位运算/只出现一次的数字/260. Single Number III.py
2,839
3.890625
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/1/17 8:40 # @Author : LI Dongdong # @FileName: 260. Single Number III.py '''''' ''' 题目分析 1.要求: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 on...
c7c49fdd8806c4b5e06b0502cb892511d82cec67
lidongdongbuaa/leetcode2.0
/数据结构与算法基础/leetcode周赛/200301/How Many Numbers Are Smaller Than the Current Number.py
1,974
4.125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/1 11:32 # @Author : LI Dongdong # @FileName: How Many Numbers Are Smaller Than the Current Number.py '''''' ''' 题目分析 1.要求: 2.理解:in a arr, count how many elem in this list < list[i], output 3.类型:array 4.确认输入输出及边界条件: input: list, length? 2<= <= 500; valu...
2d4fe689946b6ab2cfd742fc36d14df02ec05d76
lidongdongbuaa/leetcode2.0
/二分搜索/没有明确的target/658. Find K Closest Elements.py
2,454
4.03125
4
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2020/3/17 19:42 # @Author : LI Dongdong # @FileName: 658. Find K Closest Elements.py '''''' ''' 题目概述:在排序arr中,求某数x的周围k个数,若有左右相同的位置的数,取左边的数 题目考点:把取某点扩展成为求以某点为中心的数,再转化为求该段数的左端点数 解决方案: x - arr[mid] = arr[mid + k] - x 把2x当成target, arr[mid] + arr[mid + k]当作arr[m...
5c4bfde1b6c846d2ec04eaffac556ff48f713262
BiBi1495/Python-Basic
/Some_method_create_List.py
349
4.09375
4
# some methods create lists list = [] for x in range(8): list.append(2 ** x) print('list is ', list) list_1 = [2 ** x for x in range(8)] print('list 1 is ', list_1) list_2 = [x for x in range(12) if x % 2 == 0] print('list 2 is ', list_2) list_3 = [x+y for x in ['language ', 'program '] for y in ['python', 'C++']]...
02f393d79c47055ece1de9d3ff3d54d9d030244c
BiBi1495/Python-Basic
/begin_with_List.py
1,295
3.5625
4
# Co List danhsach = ["abc", 356, ["a", 'abs', 76]] print(danhsach[2][2]) # in ra phần tử cuối của phần tử cuối của danhsach. string cũng giống list nhưng phần tử của string chỉ là kí tự, phần tử của list thì đa dạng, và chúng ta có thể truy cập đến các phần tử của phần tử của nó danhsach[1] = "bibi" # có thể thay đổi ...
51a7a056f3efed50e627e4e07e0b63053e4f499e
masskro0/test_generator_drivebuild
/utils/plotter.py
1,910
4.5625
5
"""This file offers several plotting methods to visualize functions or roads.""" import matplotlib.pyplot as plt import numpy as np def plotter(control_points): """Plots every point and lines between them. Used to visualize a road. :param control_points: List of points as dict type. :return: Void. ""...
635a52e1bcc8d52b4e1da989563477c11ff0e5d7
luvjoey1996/python-algorithms
/find_max_sub.py
1,262
4.03125
4
""" 最大子数组问题 """ def find_max_sub(l: list, left, right) -> tuple: if left == right: return l[left], left, right else: average = int((right + left) / 2) left_max = find_max_sub(l, left, average) right_max = find_max_sub(l, average + 1, right) mid_max = find_mi...
c9a70f17fe29f080494dbcfec63f07e91fc5fca3
luvjoey1996/python-algorithms
/heap_sort.py
1,558
3.546875
4
import time from random import randint class Solution: def heap_sort(self, nums): s = MaxHeap(nums) return s.sort() class MaxHeap: def __init__(self, heap: list): self._heap = heap[:] self.length = len(heap) for i in reversed(range(len(self._heap) >>...
91f60b95e1932f3c323ac977f211014d8598857f
luvjoey1996/python-algorithms
/MaxCoins.py
1,008
3.6875
4
from functools import lru_cache class Solution: def max_coins(self, nums): self.nums = nums end = len(nums) return self.solution(0, end) @lru_cache(maxsize=10000) def solution(self, start, end): if start == end: return 0 else: max_coins = 0...
7d3cd7ac71594c59ddef4d16b4403b74d75c292b
duynhan39/Python
/Gg/tree.py
1,345
3.828125
4
class Node(object): def __init__(self, value): self.value = value self.next = None self.left = None self.right = None class Tree(object): def __init__(self, head): self.head = Node(head) def append(self, new_value): self.append_helper(self.head, new_value) ...
aca3a2173b859400ac79fa74daac0bfbe7938dc7
wanjapm/reggie_linear_regression
/reggie_linear_reg.py
1,075
3.515625
4
def get_y(m, b, x): #y = m*x + b return (m*x) + b def calculate_error(m,b,point): x_point = point[0] y_point = point[1] y2 = get_y(m,b,x_point) return abs(y2 - y_point) def calculate_all_error(m,b,points): error=0 for point in points: error += calculate_error(m,b,point) ret...
7cb7009e0a00388595d9c59157c13370a1a43b05
adelino-py/questoesURI
/uri1035.py
210
3.734375
4
dados = input().split(" ") A, B, C, D = dados A = int(A) B = int(B) C = int(C) D = int(D) if B>C and D>A and (C+D)>(A+B) and C>0<D and A%2 == 0: print ("Valores aceitos") else: print ("Valores nao aceitos")
420dcd8de56e92cad50cbd2a1d850390e90063ba
adelino-py/questoesURI
/uri1012.py
288
3.640625
4
dados = input().split(' ') A, B, C = dados A = float(A) B = float(B) C = float(C) T = (A*C/2) R = (3.14159*C**2) TZ = ((A+B)*C/2) Q = (B*B) RT = (A*B) print ("TRIANGULO: %.3f"%T) print ("CIRCULO: %.3f"%R) print ("TRAPEZIO: %.3f"%TZ) print ("QUADRADO: %.3f"%Q) print ("RETANGULO: %.3f"%RT)
e6a768b13da3f30cd58460701866f228f6cd1339
adelino-py/questoesURI
/uri1038.py
304
3.546875
4
dados = input().split(" ") C, Q = dados C = int(C) Q = int(Q) if C == 1: print("Total: R$ %.2f" %(4.00*Q)) elif C == 2: print("Total: R$ %.2f" %(4.50*Q)) elif C == 3: print("Total: R$ %.2f" %(5.00*Q)) elif C == 4: print("Total: R$ %.2f" %(2.00*Q)) elif C == 5: print("Total: R$ %.2f" %(1.50*Q))
51be9f429c043c11ced42ac56cc30e1a4b8fd8cf
Ali-Onar/machine-learning
/4-Decision-Tree-Regression/decision_tree_regression.py
876
3.703125
4
import pandas as pd import matplotlib.pyplot as plt import numpy as np df = pd.read_csv("decision_tree_regression_dataset.csv", sep=";") # x (seviye) ve y (ücret) eksenlerimizi oluşturalım x = df.iloc[:,0].values.reshape(-1,1) y = df.iloc[:,1].values.reshape(-1,1) #%% Decision Tree Regression from sklearn.tree imp...
e4e858c95bc33699cde7209cd595c95a74577889
rahul-deshmukhpatil/eugene
/code/feed/geturl.py
1,004
3.546875
4
#!/bin/python import urllib import urllib2 from urllib2 import Request, urlopen, URLError def text(elt): return elt.text_content().replace(u'\xa0', u' ') def get_url(url): if not url: print('URL provided to get_url is empty !!!') exit(-1) hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/...
9f0e25cd7dc42d91d35ec728703fc6b2d07b666d
alTeska/CN-Lab
/CN11.py
845
3.65625
4
#class 1 - differential equations - coffee example import matplotlib.pyplot as plt import numpy as np C = 1e3 Tr = 20 K = 0.2 # * W/K def dTcSteadState(K, C, Tr, dTcoffee): return Tr - dTcoffee * C/K def analytic_dTcoffee(t, K, C, Tr, Tc0): return Tr + (Tc0 - Tr) * np.exp(-K/C * t) def dTcoffee(K, C, Tr, T...
f751fc3dedcedc0c4d07ea1df92b2849251f81cc
triparnabh/Leetcode_Problems
/Check if a Palindrome.py
132
3.5625
4
s = "MALAYALAM" low = 0 high = len(s)-1 while low < high: if s[low] == s[high]: low+=1 high-=1 print("True")
e76692065474d552ead36ebe09474415cf807417
triparnabh/Leetcode_Problems
/Find the Fine.py
547
3.609375
4
def totFine(car_num, n, date, fine): odd = [] even = [] total_fine = 0 for i in car_num: if i%2 == 0: even.append(i) else: odd.append(i) if date % 2 == 0: for car in odd: total_fine+=250 else: for car in even: tot...
7cf461ce482bd65405955e71494916661c975bce
triparnabh/Leetcode_Problems
/Find Transition Point.py
315
3.5625
4
def transition_point(nums, N): first = nums[0] for i in range(1, N): if nums[i] == first: continue else: return i break if __name__ == '__main__': nums = [0,0,0,1,1] N = len(nums) answer = transition_point(nums, N) print (answer)
3f5fe474c61328e8b5a2438bd3f632824882fbd2
paveldavidchik/CountSubstrings
/main.py
495
3.5
4
import requests import re def main(url: str, substring: str): http_string = get_http_text(url) count = get_count_substrings(substring, http_string) print(count) def get_http_text(url: str) -> str: if not url.startswith('https://'): url = 'https://' + url return requests.get(url).text ...
7ec310a62c0505624f3f8a349eac4bad23533934
hristy93/FallingRocks
/gameplay/rock.py
743
3.96875
4
import random class Rock: def __init__(self): self.__speed = 50 def set_random_position(self, max_value): """Sets a random number from 10 to max_value which is used for setting the position of the rock. """ return random.randint(10, max_value) def set_random_shape...
fc6e1b04cce4f188cc92b055326047f86771e5a1
hristy93/FallingRocks
/gameplay/bullet.py
309
3.71875
4
class Bullet: def __init__(self): self.__speed = 50 def set_speed(self, new_speed): """Sets the bullet's speed to the value of new_speed.""" self.__speed = new_speed @property def bullet_speed(self): """Gets the bullet's speed.""" return self.__speed
fc34fea43ef21bff46c7a56fd4ec702ad9356dc8
maatheusgouveia/python-exercises
/ex1_parouimpar.py
98
3.8125
4
n1 = int(input("Digite Um número: ")) if n1%2 == 0: print ("par") else: print ("ímpar")
d36dfca52eb4717248dca4e5682a1f9aa6799a53
maatheusgouveia/python-exercises
/ex2_fizzbuzz.py
91
4.03125
4
n1 = int(input("Digite um número: ")) if n1%3 == 0: print("Fizz") else: print(n1)
7be06c00a739470f711cc4b9493a176ba1401bd5
maatheusgouveia/python-exercises
/ex1_12-07.py
150
3.609375
4
lado = int (input( "Digite o valor correspondente ao lado de um quadrado:" )) x = (lado*4) y = (lado * lado) print("perímetro:",x ," - área:",y)
d0716c01699d3012733a521f2893755e598c6c93
felipejsm/python-study
/chapter03/motorcycles.py
607
4.0625
4
#trocando o valor de um índice motorcycles = ['honda', 'yamaha', 'suzuki'] print(motorcycles) motorcycles[0] = 'triumph' print(motorcycles) #adicionando um item à lista motorcycles.append('ducati') print(motorcycles) othersMotorcycles = [] othersMotorcycles.append('harley-davidson') othersMotorcycles.append('tere...
dc4fc6f3e1179f7d5def6bc64548dc6846de9073
yashwanth15/Interviewbit_Porblems
/redundentBraces.py
452
3.515625
4
class Solution: # @param A : string # @return an integer def braces(self, A): stack=[] for i in A: if i=='(' or i=='+' or i=='-' or i=='*' or i=='/': stack.append(i) elif i==')': top=stack.pop() if top=='(': ...
331179a606ed173e50d8188346b96dfbc293a420
penguins0141/hubble3
/fuzz_test.py
398
3.59375
4
#!/usr/bin/python import socket buffers = ["A"] counter = 20 while len(buffers) <= 30: # how many elements in the array buffers.append("A"*counter) #creates new buffer in the array counter=counter+100 #add 100 to the next buffer for string in buffers: print "Buffer string length...
51f4b6ffb32e7ebc049bd56a205eaecc52726584
iambird36/python-test
/list.py
216
3.78125
4
name_list = ["Elwing", "Amy", "Bob"] print(name_list) print (name_list[0]) print (name_list[0:2]) name_list = name_list + ["Carol"] print(name_list) print(len(name_list)) for n in name_list: print("-", n)
7b5fa6cab981b82f07c39fed9be50b63de1da426
iambird36/python-test
/rock paper scissors.py
295
3.671875
4
me = int(input("scissors[0] rock[1] paper[2]")) import random com = random.randint(0, 2) trans = ["scissors", "rock", "paper"] print("yours:", trans[me]) print("com:", trans[com]) if me == com: print ("draw") elif me == (com + 1) % 3: print ("i win") else: print("i lose")
6675cf8c876656c944adfe5c4aafe16403a46116
iambird36/python-test
/define.py
357
4.0625
4
# 預設值(所有右邊的參數都要有預設值 def add(n1, n2, n3 = 1, n4 = 1): return (n1 + n2) / n3 * n4 print(add(3, 5)) print(add(3, 5, 2)) print(add(3, 5, n4 = 2)) #print(add("hello", "world")) def add_multiple(*nlist): result = 0 for n in nlist: result = result + n return result print(add_multiple(3,...
fdd21cbb3678eb28e00552e90e4f7e436683c4f5
ccoverstreet/Anemometer-Data-Server
/quickplot.py
2,822
3.734375
4
import matplotlib.pyplot as plt import numpy as np import sys def main(): print(sys.argv) if len(sys.argv) == 1: printHelp() return else: generatePlots(sys.argv[1:]) def printHelp(): print("""QuickPlot for Anemometer Data Usage: Provide a file/globbed files as an ar...
c45d3deca4dee9337adea97782b28c1023fbdb09
kancha13/programacion
/practica4/4-3.py
129
3.78125
4
a=input ("dame un numero") b=input ("dame otro numero") c=0 for i in range(a,b+1): c=c+i print i,"+", print "=",c
8933b72c7f5ad78995fde6e0778ea23055de4846
kancha13/programacion
/practica4/practica4-6.py
117
3.71875
4
altura=input("dame altura") for i in range(altura): for j in range(i+1): print"*", print ""
fcc03c8e5ffb7e35323aac6784c086ad46dbf46e
Atropos148/Jumpstart10apps
/apps/07 - Wizzard Battle/battle.py
1,592
3.625
4
from creatures import Wizard, Creature, SmallAnimal, Dragon import random import time def main(): write_header() game_loop() def write_header(): print('---------------------') print(' WIZARD BATTLE') print('---------------------') print() def game_loop(): creatures = [ Smal...
300db0ec93d3175583dc28da37b6cd27b216cd18
calpa/Algorithm
/LeetCode/242_Valid_Anagram_2.py
506
3.734375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __author__ = 'calpa' __mtime__ = '15/11/2016' """ def isAnagram(self, s, t): # HashTable hash = {} if len(s) != len(t): return False for i in s: if i in hash: hash[i] += 1 else: hash[i] = 1 for j in...
a37a1c9aad3694a1341253ce5aef4435593d0a0f
calpa/Algorithm
/Sorting/selection_sort.py
479
4
4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __author__ = 'calpa' __mtime__ = '18/10/2016' """ def selection_sort(arr): # n: the number of elements to sort n = len(arr) for i in xrange(0, n): smallest = i for x in xrange(i, n): if arr[smallest] > arr[x]: sm...
b5d12005104acec7a5550056334479d81447e841
calpa/Algorithm
/HackerRank/repeated_string.py
362
3.859375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __author__ = 'calpa' __mtime__ = '20/10/2016' """ def repeated_string(s, n): # s = string 'aba' # n = total length 10 front = (n // len(s)) * s.count('a') # 10/3 = 3 remaining = s[:(n % len(s))].count('a') # 1 < 3 return front + remaining # Tes...
147f13d08d146dfc9d4ac7d9fcf4be7b55d75d0d
calpa/Algorithm
/Sorting/quick_sort.py
530
3.6875
4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __author__ = 'calpa' __mtime__ = '20/10/2016' """ def quick_sort(arr, p, r): if p < r: q = partition(arr, p, r) quick_sort(arr, p, q-1) quick_sort(arr, q+1, r) def partition(arr, p, r): q = p for u in xrange(p, r): if arr...
98e11f6da331be62bea8cd738615434096e9d544
calpa/Algorithm
/LeetCode/383_Ransom_Note.py
483
3.609375
4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __author__ = 'calpa' __mtime__ = '19/11/2016' """ def ransom_note(ransomNote, magazine): hash = {} for i in magazine: if i in hash: hash[i] += 1 else: hash[i] = 1 for char in ransomNote: if char in hash: ...
7c55d21ce002267498f1472d8871ad3c0129291c
MattLeeTheJankster/Coin-Sorter
/coinsorter.py
448
3.59375
4
# Get input from user userNum = input("Enter an amount of money in cents. ") # Cast into int userNum = int(userNum) q = int(userNum/25) userNum = userNum - (q * 25) d = int(userNum/10) userNum = userNum - (d * 10) n = int(userNum/5) userNum = userNum - (n * 5) p = int(userNum/1) userNum = userNum - (p * 1) # Pri...
452be047238afab78a6d3e5aa26bda25718a16c1
VB6Hobbyst7/PenRobotPi
/work/flask/test.py
482
3.5625
4
# -*- coding: utf-8 -*- import VectorFontLoader #init (load index data from a.dict2) vf = VectorFontLoader.VectorFontLoader("a.dict2", "a.vect2") text = "HELLO" #open a.vect2 file and read vectors va = vf.getVectorArrayFromText(text) #multiply 100 (font standard height is 1.0) va.scale(100,100) #M = MoveTo : st...