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
57d4e31c32391b66289da0fe14c29017a35a1973
wulinlw/leetcode_cn
/初级算法/array_8.py
1,668
3.8125
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/1/array/28/ # 移动零 # 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。 # 示例: # 输入: [0,1,0,3,12] # 输出: [1,3,12,0,0] # 说明: # 必须在原数组上操作,不能拷贝额外的数组。 # 尽量减少操作次数。 class Solution(object): def moveZeroes(self, nums)...
cc15abee5c3b984f0655422e058e242d235553c3
wulinlw/leetcode_cn
/leetcode-vscode/817.链表组件.py
2,469
3.671875
4
# # @lc app=leetcode.cn id=817 lang=python3 # # [817] 链表组件 # # https://leetcode-cn.com/problems/linked-list-components/description/ # # algorithms # Medium (55.78%) # Likes: 31 # Dislikes: 0 # Total Accepted: 5.1K # Total Submissions: 9K # Testcase Example: '[0,1,2,3]\n[0,1,3]' # # 给定一个链表(链表结点包含一个整型值)的头结点 head。 ...
20cff1c9700d9009a225c7413e248a2ee1c48322
wulinlw/leetcode_cn
/leetcode-vscode/912.排序数组.py
5,906
3.84375
4
# # @lc app=leetcode.cn id=912 lang=python3 # # [912] 排序数组 # # https://leetcode-cn.com/problems/sort-an-array/description/ # # algorithms # Medium (53.09%) # Likes: 68 # Dislikes: 0 # Total Accepted: 29.9K # Total Submissions: 52.7K # Testcase Example: '[5,2,3,1]' # # 给你一个整数数组 nums,将该数组升序排列。 # # # # # # # ...
3e400e6a75eb427dc43cce66ff23c5e6bf40a9a2
wulinlw/leetcode_cn
/初级算法/mathematics_1.py
1,133
3.875
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/25/math/60/ # Fizz Buzz # 写一个程序,输出从 1 到 n 数字的字符串表示。 # 1. 如果 n 是3的倍数,输出“Fizz”; # 2. 如果 n 是5的倍数,输出“Buzz”; # 3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。 # 示例: # n = 15, # 返回: # [ # "1", # "2", # "Fizz", # ...
6719f2cc32c1a8cd9f06575e3c730105c15b3fc5
wulinlw/leetcode_cn
/字节跳动/array-and-sorting_8.py
2,455
3.890625
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/bytedance/243/array-and-sorting/1036/ # 朋友圈 # 班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友。所谓的朋友圈,是指所有朋友的集合。 # 给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系。如果M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道。你必须输出所有学生中的已知的...
177cb9cffdfe5c9fe8035ec10664006982f49606
wulinlw/leetcode_cn
/初级算法/other_2.py
1,212
4.0625
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/26/others/65/ # 汉明距离 # 两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目。 # 给出两个整数 x 和 y,计算它们之间的汉明距离。 # 注意: # 0 ≤ x, y < 231. # 示例: # 输入: x = 1, y = 4 # 输出: 2 # 解释: # 1 (0 0 0 1) # 4 (0 1 0 0) # ↑ ↑ # 上面的箭头指出了对应二...
c842b9d5b5342e91b9e84dbeecf698e1a8ce8570
wulinlw/leetcode_cn
/初级算法/mathematics_2.py
1,763
3.984375
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/25/math/61/ # 计数质数 # 统计所有小于非负整数 n 的质数的数量。 # 示例: # 输入: 10 # 输出: 4 # 解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 。 # 厄拉多塞筛法 # 西元前250年,希腊数学家厄拉多塞(Eeatosthese)想到了一个非常美妙的质数筛法, # 减少了逐一检查每个数的的步骤,可以比较简单的从一大堆数字之中,筛选出质数来,这方法...
8930fdd2af4503f19f5eea56e0e004319275a342
wulinlw/leetcode_cn
/程序员面试金典/面试题16.16.部分排序.py
2,042
4.03125
4
# #!/usr/bin/python # #coding:utf-8 # # 面试题16.16.部分排序 # # https://leetcode-cn.com/problems/sub-sort-lcci/ # # 给定一个整数数组,编写一个函数,找出索引m和n,只要将索引区间[m,n]的元素排好序,整个数组就是有序的。注意:n-m尽量最小,也就是说,找出符合条件的最短序列。函数返回值为[m,n],若不存在这样的m和n(例如整个数组是有序的),请返回[-1,-1]。 # 示例: # 输入: [1,2,4,7,10,11,7,12,6,7,16,18,19] # 输出: [3,9] # # 提示: # # 0 # #...
a7a068cb60a7c34934ca3980b45ab240ac077b7e
wulinlw/leetcode_cn
/leetcode-vscode/892.三维形体的表面积.py
1,718
3.671875
4
# # @lc app=leetcode.cn id=892 lang=python3 # # [892] 三维形体的表面积 # # https://leetcode-cn.com/problems/surface-area-of-3d-shapes/description/ # # algorithms # Easy (55.73%) # Likes: 68 # Dislikes: 0 # Total Accepted: 8.6K # Total Submissions: 14.3K # Testcase Example: '[[2]]' # # 在 N * N 的网格上,我们放置一些 1 * 1 * 1  的立方体...
2a7878e20f2170d581b6defd02672e1d886cf7e6
wulinlw/leetcode_cn
/程序员面试金典/面试题02.04.分割链表.py
1,492
3.921875
4
#!/usr/bin/python #coding:utf-8 # 面试题 02.04. 分割链表 # 编写程序以 x 为基准分割链表,使得所有小于 x 的节点排在大于或等于 x 的节点之前。如果链表中包含 x,x 只需出现在小于 x 的元素之后(如下所示)。 # 分割元素 x 只需处于“右半部分”即可,其不需要被置于左右两部分之间。 # 示例: # 输入: head = 3->5->8->5->10->2->1, x = 5 # 输出: 3->1->2->10->5->5->8 # https://leetcode-cn.com/problems/partition-list-lcci/ # Definition for...
ecfa4146a927249cf7cb510dbf14432cd2bb84a7
wulinlw/leetcode_cn
/剑指offer/30_包含min函数的栈.py
1,296
4.125
4
#!/usr/bin/python #coding:utf-8 # // 面试题30:包含min函数的栈 # // 题目:定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的min # // 函数。在该栈中,调用min、push及pop的时间复杂度都是O(1)。 class StackWithMin: def __init__(self): self.stack = [] self.min_stack = [] def push(self, node): # write code here self.stack.append(node) ...
9e2c9cc88b442a408d79363289c2cfc3905d13c4
wulinlw/leetcode_cn
/剑指offer/17_打印1到最大的n位数.py
1,245
3.6875
4
#!/usr/bin/python #coding:utf-8 # 打印1到最大的n位数 # 输入数字n, 按顺序打印从1最大的n位十进制数 # 比如输入3, 则打印出1、2、3、到最大的3位数即999 class Solution: def Print1ToMaxOfNDigits(self, n): for i in range(10): #套路写法,生产每一位的0-9,从最左边开始生成 self.recursion(str(i), n, 0) #每个数字的开头 # s 数字开...
1292292f8f86615a11e933a7234211ad43a71da8
wulinlw/leetcode_cn
/top-interview-quesitons-in-2018/dynamic-programming_1.py
1,113
3.953125
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/featured/card/top-interview-quesitons-in-2018/272/dynamic-programming/1174/ # 至少有K个重复字符的最长子串 # 找到给定字符串(由小写字符组成)中的最长子串 T , 要求 T 中的每一字符出现次数都不少于 k 。输出 T 的长度。 # 示例 1: # 输入: # s = "aaabb", k = 3 # 输出: # 3 # 最长子串为 "aaa" ,其中 'a' 重复了 3 次。 # 示例 2: # 输入: # s = "a...
fcc7f51524ae8699c60101b37ff9bbcffdfa1263
wulinlw/leetcode_cn
/剑指offer/44_数字序列中某一位的数字.py
2,798
3.75
4
#!/usr/bin/python #coding:utf-8 # // 面试题44:数字序列中某一位的数字 # // 题目:数字以0123456789101112131415…的格式序列化到一个字符序列中。在这 # // 个序列中,第5位(从0开始计数)是5,第13位是1,第19位是4,等等。请写一 # // 个函数求任意位对应的数字。 class Solution: def digitAtIndex(self, index): if index < 0: return -1 digits = 1 while True: le...
93980a2f1b9d778ff907998b6fb722722ec28d73
wulinlw/leetcode_cn
/递归/recursion_1_1.py
1,304
4.15625
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/orignial/card/recursion-i/256/principle-of-recursion/1198/ # 反转字符串 # 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。 # 不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。 # 你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。 # 示例 1: # 输入:["h","e","l","l","o"] # 输出:["o","l",...
b3328bb716cac18bf8e375f48de6ae5d67faa44b
wulinlw/leetcode_cn
/中级算法/tree_6.py
2,059
3.796875
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-medium/32/trees-and-graphs/90/ # 岛屿的个数 # 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量。一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的。你可以假设网格的四个边均被水包围。 # 示例 1: # 输入: # 11110 # 11010 # 11000 # 00000 # 输出: 1 # 示例 2: # 输入: # 11000 # ...
bacfbc3a4a068cf87954be2a53e0a6ab44ba41bc
wulinlw/leetcode_cn
/链表/linked-list_5_3.py
2,469
4.125
4
#!/usr/bin/python # coding:utf-8 # https://leetcode-cn.com/explore/learn/card/linked-list/197/conclusion/764/ # 扁平化多级双向链表 # 您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表。这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示。 # 扁平化列表,使所有结点出现在单级双链表中。您将获得列表第一级的头部。 # 示例: # 输入: # 1---2---3---4---5---6--NULL # | # ...
43d875814e422cab3a1d28b38b8862ef137e70ae
wulinlw/leetcode_cn
/剑指offer/28_对称的二叉树.py
2,014
3.671875
4
#!/usr/bin/python #coding:utf-8 # // 面试题28:对称的二叉树 # // 题目:请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和 # // 它的镜像一样,那么它是对称的。 class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def isSymmetrical(self, root): if not root:return True ...
b7fce39adf1ba1fa6029dda276e2fde9eb8277ec
wulinlw/leetcode_cn
/剑指offer/23_链表中环的入口结点.py
1,404
3.796875
4
#!/usr/bin/python #coding:utf-8 # // 面试题23:链表中环的入口结点 # // 题目:一个链表中包含环,如何找出环的入口结点?例如,在图3.8的链表中, # // 环的入口结点是结点3。 class ListNode: def __init__(self, x=None): self.val = x self.next = None class Solution: def initlinklist(self, nums): head = ListNode(nums[0]) re = head for...
4154a18778d1e344a20d388bb08ce7d33022adce
wulinlw/leetcode_cn
/leetcode-vscode/78.子集.py
1,086
3.578125
4
# # @lc app=leetcode.cn id=78 lang=python3 # # [78] 子集 # # https://leetcode-cn.com/problems/subsets/description/ # # algorithms # Medium (76.55%) # Likes: 493 # Dislikes: 0 # Total Accepted: 69.2K # Total Submissions: 90.1K # Testcase Example: '[1,2,3]' # # 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集)。 # # 说明:解集不能包含重复...
80082f949d1589ddc0a79a9067b95413e873b4f4
wulinlw/leetcode_cn
/leetcode-vscode/406.根据身高重建队列.py
1,933
3.546875
4
# # @lc app=leetcode.cn id=406 lang=python3 # # [406] 根据身高重建队列 # # https://leetcode-cn.com/problems/queue-reconstruction-by-height/description/ # # algorithms # Medium (62.74%) # Likes: 272 # Dislikes: 0 # Total Accepted: 21.8K # Total Submissions: 34.2K # Testcase Example: '[[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]...
e727d73d45d67bf07c8a7cf7bcf3103d8acd75b4
wulinlw/leetcode_cn
/数组和字符串/array_6.py
939
3.75
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/featured/card/array-and-string/202/conclusion/792/ # 杨辉三角 II # 给定一个非负索引 k,其中 k ≤ 33,返回杨辉三角的第 k 行。 # 在杨辉三角中,每个数是它左上方和右上方的数的和。 # 示例: # 输入: 3 # 输出: [1,3,3,1] # 进阶: # 你可以优化你的算法到 O(k) 空间复杂度吗? class Solution(object): def getRow(self, rowIndex): "...
e17240c468f25e13762598f4f7c18bb9fbacd888
wulinlw/leetcode_cn
/二叉树/search-tree_1_2.py
1,994
4.09375
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/learn/card/introduction-to-data-structure-binary-search-tree/64/introduction-to-a-bst/172/ # 二叉搜索树迭代器 # 实现一个二叉搜索树迭代器。你将使用二叉搜索树的根节点初始化迭代器。 # 调用 next() 将返回二叉搜索树中的下一个最小的数。 # 示例: # BSTIterator iterator = new BSTIterator(root); # iterator.next(); // 返回 ...
1926f0d51153da212fbfd132588b7547ca9b9e9d
wulinlw/leetcode_cn
/初级算法/linkedList_4.py
1,718
4.25
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/6/linked-list/44/ # 合并两个有序链表 # 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 # 示例: # 输入:1->2->4, 1->3->4 # 输出:1->1->2->3->4->4 # 新建链表,对比两个链表指针,小的放新链表中,直到某条链表结束, # 将另一条链表剩余部分接入新链表 # Definition for singly-l...
1270af1e1c684481ba5488a2fcff3aa3ca656284
wulinlw/leetcode_cn
/leetcode-vscode/637.二叉树的层平均值.py
1,670
3.703125
4
# # @lc app=leetcode.cn id=637 lang=python3 # # [637] 二叉树的层平均值 # # https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/description/ # # algorithms # Easy (63.16%) # Likes: 98 # Dislikes: 0 # Total Accepted: 14.5K # Total Submissions: 22.9K # Testcase Example: '[3,9,20,15,7]' # # 给定一个非空二叉树, 返回一个由每层节...
096fdd8e7212763ede543a13cdad2240dd9f91ae
wulinlw/leetcode_cn
/dynamic-programming/dynamic-programming_63.py
2,054
3.75
4
#!/usr/bin/python #coding:utf-8 # 63. 不同路径 II # 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为“Start” )。 # 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为“Finish”)。 # 现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径? # 网格中的障碍物和空位置分别用 1 和 0 来表示。 # 说明:m 和 n 的值均不超过 100。 # 示例 1 # 输入: # [ #   [0,0,0], #   [0,1,0], #   [0,0,0] # ] # 输出: 2 # 解释: # 3x3 网格的正中间...
ecaa303c54ccfc6abc2d3e1c76799df9dabe7794
wulinlw/leetcode_cn
/程序员面试金典/面试题04.01.节点间通路.py
2,549
3.765625
4
# #!/usr/bin/python # #coding:utf-8 # # 面试题04.01.节点间通路 # # https://leetcode-cn.com/problems/route-between-nodes-lcci/ # # 节点间通路。给定有向图,设计一个算法,找出两个节点之间是否存在一条路径。 # 示例1: # # 输入:n = 3, graph = [[0, 1], [0, 2], [1, 2], [1, 2]], start = 0, target = 2 # 输出:true # # # 示例2: # # 输入:n = 5, graph = [[0, 1], [0, 2], [0, 4]...
1ffbfbbbc0ea0c6f4725b89363464d734a17cd94
wulinlw/leetcode_cn
/剑指offer/3_数组中重复的数字.py
935
3.8125
4
#!/usr/bin/python #coding:utf-8 # 数组中重复的数字 # 在一个长度为n的数组里的所有数字都在0到n-1的范围内。 # 数组中某些数字是重复的,但不知道有几个数字是重复的。也不知道每个数字重复几次。 # 请找出数组中任意一个重复的数字。 # 例如,如果输入长度为7的数组{2,3,1,0,2,5,3},那么对应的输出是重复的数字2或者3。 class Solution(object): def duplicate(self, nums): if len(nums)== 0: return False re = [] for...
bb2dd47c253fd1d7226b49f6a73d0f93658334c8
wulinlw/leetcode_cn
/top-interview-quesitons-in-2018/string_3.py
1,781
3.65625
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/featured/card/top-interview-quesitons-in-2018/275/string/1138/ # 单词拆分 # 给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 # 说明: # 拆分时可以重复使用字典中的单词。 # 你可以假设字典中没有重复的单词。 # 示例 1: # 输入: s = "leetcode", wordDict = ["leet", "code"] # 输出: true...
7799a49165b44fdc5f7c6064432c6204f384286b
wulinlw/leetcode_cn
/leetcode-vscode/563.二叉树的坡度.py
1,736
3.875
4
# # @lc app=leetcode.cn id=563 lang=python3 # # [563] 二叉树的坡度 # # https://leetcode-cn.com/problems/binary-tree-tilt/description/ # # algorithms # Easy (53.09%) # Likes: 54 # Dislikes: 0 # Total Accepted: 8.9K # Total Submissions: 16.7K # Testcase Example: '[1,2,3]' # # 给定一个二叉树,计算整个树的坡度。 # # 一个树的节点的坡度定义即为,该节点左子树的...
66fbee2c03751ac6ca76c7b9e1b1449cc609597d
wulinlw/leetcode_cn
/leetcode-vscode/98.验证二叉搜索树.py
4,208
3.8125
4
# # @lc app=leetcode.cn id=98 lang=python3 # # [98] 验证二叉搜索树 # # https://leetcode-cn.com/problems/validate-binary-search-tree/description/ # # algorithms # Medium (29.10%) # Likes: 543 # Dislikes: 0 # Total Accepted: 103.5K # Total Submissions: 340.3K # Testcase Example: '[2,1,3]' # # 给定一个二叉树,判断其是否是一个有效的二叉搜索树。 # ...
d8ee8504bbeea0dc8d222d93e9a13c16ff5ca4d8
wulinlw/leetcode_cn
/leetcode-vscode/820.单词的压缩编码.py
4,185
3.796875
4
# # @lc app=leetcode.cn id=820 lang=python3 # # [820] 单词的压缩编码 # # https://leetcode-cn.com/problems/short-encoding-of-words/description/ # # algorithms # Medium (40.03%) # Likes: 70 # Dislikes: 0 # Total Accepted: 14.1K # Total Submissions: 32.8K # Testcase Example: '["time", "me", "bell"]' # # 给定一个单词列表,我们将这个列表编码...
15acb129012387c2a2c05e982a16a9e2d454660a
wulinlw/leetcode_cn
/leetcode-vscode/897.递增顺序查找树.py
2,420
3.9375
4
# # @lc app=leetcode.cn id=897 lang=python3 # # [897] 递增顺序查找树 # # https://leetcode-cn.com/problems/increasing-order-search-tree/description/ # # algorithms # Easy (65.76%) # Likes: 58 # Dislikes: 0 # Total Accepted: 8K # Total Submissions: 12.1K # Testcase Example: '[5,3,6,2,4,null,8,1,null,null,null,7,9]' # # 给...
3192958328b62328c5bcc2c89a2ef2fc53ba001b
wulinlw/leetcode_cn
/leetcode-vscode/606.根据二叉树创建字符串.py
2,203
3.640625
4
# # @lc app=leetcode.cn id=606 lang=python3 # # [606] 根据二叉树创建字符串 # # https://leetcode-cn.com/problems/construct-string-from-binary-tree/description/ # # algorithms # Easy (52.76%) # Likes: 98 # Dislikes: 0 # Total Accepted: 9.4K # Total Submissions: 17.7K # Testcase Example: '[1,2,3,4]' # # 你需要采用前序遍历的方式,将一个二叉树转换...
940b4d34f8c3c69f861cb1073cb9935f503835bf
wulinlw/leetcode_cn
/leetcode-vscode/350.两个数组的交集-ii.py
1,630
3.765625
4
# # @lc app=leetcode.cn id=350 lang=python3 # # [350] 两个数组的交集 II # # https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/description/ # # algorithms # Easy (48.66%) # Likes: 315 # Dislikes: 0 # Total Accepted: 103.1K # Total Submissions: 205.9K # Testcase Example: '[1,2,2,1]\n[2,2]' # # 给定两个数组,编写一个函数来...
2d2c4fe3cd12f51c41aeb1dea6920d4d2752bb53
wulinlw/leetcode_cn
/剑指offer/43_从1到n整数中1出现的次数.py
3,313
3.640625
4
#!/usr/bin/python #coding:utf-8 # // 面试题43:从1到n整数中1出现的次数 # // 题目:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数。例如 # // 输入12,从1到12这些整数中包含1 的数字有1,10,11和12,1一共出现了5次。 class Solution: def NumberOf1Between1AndN_Solution(self, n): # https://blog.csdn.net/ggdhs/article/details/90311852 # 如果要计算百位上1出现的次数,它要受到3方面的影响:百位上的数...
db50eae1594cc0bc7ee8f331ca3b6383a3217288
wulinlw/leetcode_cn
/递归/recursion_5_3.py
4,062
3.9375
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/orignial/card/recursion-i/260/conclusion/1233/ # 不同的二叉搜索树 II # 给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树。 # 示例: # 输入: 3 # 输出: # [ # [1,null,3,2], # [3,2,null,1], # [3,1,null,null,2], # [2,1,3], # [1,null,2,null,3] # ] # 解释: # 以上的输出对应以下 5 种不同结构的二叉搜...
b43fa3334180039300923931d9259fe5a6ba832e
wulinlw/leetcode_cn
/leetcode-vscode/69.x-的平方根.py
1,050
3.671875
4
# # @lc app=leetcode.cn id=69 lang=python3 # # [69] x 的平方根 # # https://leetcode-cn.com/problems/sqrtx/description/ # # algorithms # Easy (37.57%) # Likes: 364 # Dislikes: 0 # Total Accepted: 126.8K # Total Submissions: 335.5K # Testcase Example: '4' # # 实现 int sqrt(int x) 函数。 # # 计算并返回 x 的平方根,其中 x 是非负整数。 # # 由...
72aadd6ad7c82acd94fd6500aea2f08d406da84e
wulinlw/leetcode_cn
/哈希表/hash-table_1_1.py
2,228
3.984375
4
#!/usr/bin/python # coding:utf-8 # https://leetcode-cn.com/explore/learn/card/hash-table/203/design-a-hash-table/799/ # 设计哈希集合 # 不使用任何内建的哈希表库设计一个哈希集合 # 具体地说,你的设计应该包含以下的功能 # add(value):向哈希集合中插入一个值。 # contains(value) :返回哈希集合中是否存在这个值。 # remove(value):将给定值从哈希集合中删除。如果哈希集合中没有这个值,什么也不做。 # 示例: # MyHashSet hashSet = new My...
54cd0bace7d37beaf42ea3520896257a5bd3d19b
wulinlw/leetcode_cn
/中级算法/sorting-and-searching_5.py
2,508
3.765625
4
#!/usr/bin/python #coding:utf-8 # https://leetcode-cn.com/explore/interview/card/top-interview-questions-medium/50/sorting-and-searching/100/ # 在排序数组中查找元素的第一个和最后一个位置 # 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。 # 你的算法时间复杂度必须是 O(log n) 级别。 # 如果数组中不存在目标值,返回 [-1, -1]。 # 示例 1: # 输入: nums = [5,7,7,8,8,10],...
5f492700d7482fa2df271ec9088f8f06fbeeb568
Bhavya-Tripathi/ComputerNetworks
/Assignment-3/test.py
1,245
3.765625
4
import socket,sys print("Setting up server: ") #Get hostname,IP sock = socket.socket() hostname = socket.gethostname() ip = socket.gethostbyname(hostname) port = 6969 sock.bind((hostname,port)) #binds IP of localhost to port print(hostname, '({})'.format(ip)) name = input('Enter your name:') sock.listen(1) #to locate...
efa5b93f22db52d9dfe98f8a95f3c8da4866aa24
VictorSHJ/fundamentos-python
/palindroma.py
1,116
4.125
4
# GRUPO 2: # Crea una funcion que dado una palabra diga si es palindroma o no. def palindroma(palabra): print(f"Palabra Normal: {palabra}, Palabra Invertida: {palabra[::-1]}") if palabra == palabra[::-1]: print("Es palindroma") else: print("No es palindroma") print("Ingrese una palabra :"...
893ad93e796a1e7ac5fd1df23c8ab4a4c432a454
SebastianStaab/AEMLproject
/tetris/testing.py
806
3.515625
4
cols = 10 rows = 20 board = [ [ 0 for x in range(cols) ] for y in range(rows) ] board += [[ 1 for x in range(cols)]] def join_matrixes(mat1, mat2, mat2_off): off_x, off_y = mat2_off for cy, row in enumerate(mat2): for cx, val in enumerate(row): mat1[cy+off_y-1 ][cx+off_...
b7908c0d09dd1a60a6c355b67ad4d7f2b5b324a6
jamesdschmidt/exercises-for-programmers
/23-troubleshooting-car-issues/troubleshooting_car_issues.py
1,024
3.984375
4
answer = input("Is the car silent when you turn the key? ") if answer.lower().startswith("y"): answer = input("Are the battery terminals corroded? ") if answer.lower().startswith("y"): print("Clean terminals and try starting again.") else: print("Replace cables and try again.") else: ans...
df0d8ad8924c8948c854619cef38c87f90a74e7e
jamesdschmidt/exercises-for-programmers
/11-currency-conversion/currency_conversion.py
309
3.875
4
DOLLAR_RATE = 100 euros = int(input("How many euros are you exchanging? ")) exchange_rate = float(input("What is the exchange rate? ")) dollars = round((euros * exchange_rate) / DOLLAR_RATE, 2) print(f"{euros} euros at an exchange rate of {exchange_rate:,.2f} is\n" f"{dollars:,.2f} U.S. dollars.")
a81d2c7a6c3213eb61126ec23759d462e0b6862c
jamesdschmidt/exercises-for-programmers
/14-tax-calculator/tax_calculator.py
305
3.75
4
TAX_RATE = 0.055 amount = float(input("What is the order amount? ")) state = input("What is the state? ") total = amount output = "" if "wi" == state.lower(): tax = amount * TAX_RATE output = f"The tax is ${tax:,.2f}.\n" total += tax output += f"The total is ${total:,.2f}" print(output)
e75d330b5e9e8fa368266108785fad07875ffd97
jamesdschmidt/exercises-for-programmers
/16-legal-driving-age/legal_driving_age.py
119
4.09375
4
age = int(input("What is your age? ")) print("You", "are not" if age < 16 else "are", "old enough to legally drive.")
bbf1b7caf79ccf7f09fa42a45915a12feb88eb8d
jamesdschmidt/exercises-for-programmers
/13-determining-compound-interest/determining_compound_interest.py
503
3.734375
4
principal = float(input("What is the principal amount? ")) rate = float(input("What is the rate? ")) years = int(input("What is the number of years? ")) compound = int(input("What is the number of times the interest\n" "is compounded per year?")) amount = round(principal * ((1 + (rate / 100) / com...
14a129dab9189feff13e5be95e38aae5fefb5b36
dwighthubbard/ipython_embedded_notebooks
/intro/3_tail.py
754
3.828125
4
# Blink an LED on pin 18. # Connect a low-ohm (like 360 ohm) resistor in series with the LED. import RPi.GPIO as GPIO import time # A variable so we can change the PIN number for this script in once place # if we move the LED to a different pin. PIN = 7 # Set the pin to do output GPIO.setmode(GPIO.BCM) GPIO.setup(PI...
b107480b098897c85a77f5bfa88ea20a4f78a497
AlNiLo/LearnPython
/HomeW/!!!!L2_test_classroom_list.py
1,326
3.875
4
quest = input('По какому классу вывести оценки? ') school = [ {'class':[ {'1':[ {'a':[1, 3, 4, 4, 3, 5, 3], 'b':[1, 2, 4, 4, 3, 4, 4], 'c':[1, 2, 2, 5, 4, 5, 5] } ], ...
e5f82bbb3538305b49f22f9c1e8530a0e87a20fa
kardeepak/protostar
/format0.py
228
3.609375
4
import struct # padding will pad and print an integer fron the stack. It will print 64 integers padding = "%64d" # Value that will be written to the target variable value = struct.pack("I", 0xdeadbeef) print(padding + value)
498cdb043ed9f878303fedb8d72019ce27d8faa0
CodecoolBP20173/game_enhancement
/tictac_test.py
6,627
3.71875
4
import string field = [] player_x_win = 0 player_o_win = 0 def print_field(): # print empty field with nested lists alphabet = string.ascii_lowercase print("\n" * 50) for i in range(field_size): field.append([" "]) for j in range(field_size): field[i].append(" ") ...
cfba2c4ac2beb767417b1e8e46486dea23cdf26e
adamcharnock/repose
/repose/validators.py
1,626
3.703125
4
from booby.validators import * import six class Range(Integer): """This validator forces fields values to be within a given range (inclusive)""" def __init__(self, min=None, max=None): self.min = min self.max = max @nullable def validate(self, value): if self.max is not None:...
5a0be252fff51c358f1360716f892c69078c98a1
mirzaevolution/Python-Basics
/PythonApplication2/Statements.py
790
3.890625
4
import constant """ Python Program #1 """ #line continuation statement number1 = 1 + 2 + \ 3 + 4 + \ 5 + 6 number2 = (1 + 2 + 3 + 4 + 5 + 6) print(number1) print(number2) # One line assignment var1,var2,var3 = 1,12.4,"Mirza Ghulam Rasyid" print(var1) print(var2) print...
ca5941b7b2355135eb03c3d8880a741db9a221f2
November29th/ObjectedOrientedCards
/objectOrientedCards.py
1,719
3.796875
4
from random import* class Card(object): def __init__(self, suit = None, value = None): self.value = value class Diamond(Card): def __init__(self): super(Diamond, self).__init__("Diamond", 4) class Heart(Card): def __init__(self): super(Heart, self).__init__("Heart", 3) class Club...
20bb2a14fbb695fa1d1868147e8e2afc147cecc3
fatychang/pyimageresearch_examples
/ch10 Neural Network Basics/perceptron_example.py
1,157
4.25
4
# -*- coding: utf-8 -*- """ Created on Mon Dec 9 12:56:47 2019 This is an example for runing percenptron structure to predict bitwise dataset You may use AND, OR and XOR in as the dataset. A preceptron class is called in this example. An example from book deep learning for computer vision with Python ch10 @author: ...
fd608e74e03f957482ac06f6b55b9f2f3363434a
fatychang/pyimageresearch_examples
/barcode-detection-guide/detect_barcode.py
2,746
3.578125
4
# -*- coding: utf-8 -*- """ Created on Tue Feb 4 13:04:46 2020 This script demonstrates the technique to detect the barcode using computer vision and image processing technique A edge detection approach is implemented in this script with opencv This sample is inspired by the post from pyinagesearch @author: jscha...
b7c3cf717dea0f7c9b95599c99e691e6b0fe16ea
amcatlin/CSCI156-ExceptionHandling
/ExceptionHandling answers.py
1,155
3.859375
4
__author__ = 'Alicia' y = 'Enter SS#: ' inputstring = 'Please enter a valid social security number of the form ###-##-#### including the dashes: ' def question(s): social = input(s).strip() try: AAA, GG, SSSS = social.split('-') area = int(AAA) group = int(GG) serial = int(SSSS...
84f18c6f127360133af6802d2cd698551d6a6665
rarafa/crypto-course
/rot13.py
778
3.765625
4
#!/usr/bin/python3 import sys def rot13(input): output="" for i in input: if i.isalpha(): if i.islower(): if (ord(i)+13)%ord('z') < ord('a'): output += chr( ((ord(i)+13)%ord('z'))+ord('a') ) else: output += chr( (ord(i...
c83a41d51e6061033feaf6054f63c3f570c1f03b
junejunejune/numpy_practice
/sort.py
460
3.671875
4
import numpy as np def selection_sort(x): for i in range(len(x)): swap = i + np.argmin(x[i:]) (x[i], x[swap]) = (x[swap], x[i]) return x def bogosort(x): while np.any(x[:-1] > x[1:]): np.random.shuffle(x) return x x = np.array([2,1,4,3,5]) print(selection_sort(x)) x = np.arra...
b7a04a3f5513cfa9d6aca9f3cb548726ec953326
Hegerstrand/energyMapperOld
/Python/venv/Lib/site-packages/copyfile/copyfile.py
1,403
3.625
4
import os import shutil import logging def touch(fname, times=None): """Creates an empty file at fname, creating path if necessary Answer taken from Stack Overflow http://stackoverflow.com/a/1160227 User: ephemient http://stackoverflow.com/users/20713 License: CC-BY-SA 3.0 https://creativecommons.org/...
f2e5accccddc156ccc92d48cca4b7bc2a1f50d4f
szwagiers/sqlite
/ccsqlite/lesson3.py
319
3.96875
4
import sqlite3 conn = sqlite3.connect("database.db") # put cursor c = conn.cursor() # execute sql directly to database c.execute("CREATE TABLE IF NOT EXISTS books (title TEXT,pages INTEGER)") c.execute('INSERT INTO books VALUES("The Count of Monte Cristo",1316)') conn.commit() c.execute('SELECT * FROM books')
2423751e0607aa434d00d5e909e19126ac366ee9
PPCCCSCS/Flippant
/FlippantTutor.py
91,171
4.28125
4
""" File: FlippantTutor.py The program teaches users how to play the dice game Flippant via a simulated game with one to three computer-controlled opponents. Their choices are chosen randomly, so players shouldn't expect to learn strategies for competing with skilled players, but this program should provide an ...
feea22a9815e0067f55718d5c59f90f16a5c4c69
hannahmok/webhax_samples
/04-shellsanitization-better/index.py
810
3.515625
4
#!/usr/bin/env python3 import os import sys import urllib.parse # parse the query string (?x=1&y=2) into the parameters dict {'x': ['1'], 'y': ['2']} parameters = urllib.parse.parse_qs(os.environ['QUERY_STRING']) # handle ?query=xx to search for text if 'query' in parameters: print('Content-type: text/plain\n') ...
f963c5c6e26976b826456b634c80ed388d7cde55
ptsteadman/qfo-algo-console
/strategy/monkey.py
370
3.6875
4
import random class Monkey(object): """ Silly monkey strategy every freq tick roll the dice To instantiate a 30 tick monkey: >>> monkey = Monkey(30) """ def __init__(self, freq): self.freq = freq def __call__(self, tick): if tick.index % self.freq: return None ...
a73e83cd06a469cbbea8440e836f359715d1ff08
ptsteadman/qfo-algo-console
/strategy/bollinger.py
920
3.53125
4
class Bollinger(object): """ Bollinger's band trading strategy, for Mean Reversion or Breakout Bollinger's band take 2 parameters the period N of the underlying moving average and the widht of the band K. To instantiate a 20 days, 2 standard dev: >>> bollinger = Bollinger(20, 2, reversion) ""...
847ace6bebef81ef053d6a0268fa54e36072dd72
chenshaobin/python_100
/ex2.py
1,113
4.1875
4
#!/usr/bin/python # -*- coding: utf-8 -*- """ # Write a program which can compute the factorial of a given numbers. # The results should be printed in a comma-separated sequence on a single line.Suppose the following input is supplied to the program: 8 Then, the output should be:40320 """ # 使用while """ n = int...
baa5ff5f08103e624b90c7a754f0f5cc60429f0e
chenshaobin/python_100
/ex9.py
581
4.15625
4
#!/usr/bin/python # -*- coding: utf-8 -*- """ # Write a program that accepts sequence of lines as input # and prints the lines after making all characters in the sentence capitalized. """ # solution1 """ lst = [] while True: x = input("Please enter one word:") if len(x) == 0: break lst.appen...
04d0d49313ad3fd020a1dd5364f663819160c825
wongxinjie/python-tools
/profile/timer.py
1,177
3.5625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """程序片函数运行时间测量模块 usage: from timer import Timer ... with Timer(): ... """ import gc import timeit class Timer(object): def __init__(self, timer=None, disable_gc=False, verbose=False, program=None): if timer is None: ...
fd3a3adc3b657f5f3d72697827658c1ecf804ea9
seanxwh/github
/Python/miscellaneous/Nerual_Network.py
5,830
4.09375
4
#A neural network implementation for data/labels classification using Python. User can train the network #by provide data that has labels in it. User can also fine tune the network by modifying it parameters (e.ghidden layers, learning rate, etc) # Package imports import matplotlib.pyplot as plt import math import num...
8c551099820670650129116ba923151ccffcc6dc
Agugu95/AlgoPy
/algo_py/BridgeOnTrucks.py
652
3.78125
4
from collections import deque def solution(bridge_length, weight, truck_weights): answer = 0 waited_truck = deque(truck_weights) cur_bridge = [0] * bridge_length cur_weight = 0 while cur_bridge: cur_weight -= cur_bridge.pop(0) if waited_truck: if(cur_weight + waited_tr...
ab46a3b79cb7eeeba170fd2db174876fca14b900
ritik1234/calculator
/calculatorgui.py
5,091
3.71875
4
from tkinter import * import math root = Tk() def click(event): global value text = event.widget.cget("text") if text == "sin": value.set(math.sin(float(exp.get()))) exp.update() elif text == "cos": value.set(math.cos(float(exp.get()))) exp.update() elif t...
855fab989e0c28a10cfd7459bfcf6cd03091a061
AlibekAbd/-
/Gauss.py
826
3.71875
4
import numpy as np import random import scipy.linalg as sla n = int(input()) A = np.random.rand(n,n) f = np.random.rand(n) #diagonal dimension for i in range(0,n): summa = 0 for j in range(0,n): summa += abs(A[i][j]) c = random.uniform(1,2) A[i][i] = summa + c def forward_elimination(A, f, n): for k in range(...
932dffef241b7aadab1551b63db501e7146457c0
Ankirama/Epitech
/B5---Java-I-Programming/JWeb/data/initDB.py
5,787
4.09375
4
import sqlite3 import sys class Database: ''' Helper to use sqlite3 and init our database ''' def __init__(self, dbname): ''' It will connect to the database name (or create it) and create (if not exists) our tables @param: dbname: database name ''' try: ...
0a0e107f75b9549da0db80273d81ff7b4e84e88a
alanmanderson/advent_of_code_2020
/2/validate_passwords.py
1,435
3.515625
4
INPUT_FILE = 'my_input.txt' def read_file(filename): with open(filename, 'r') as fp: data = [] for line in fp: data.append(line.strip().split(': ')) return data def old_valid_passwords(data): valid_passwords = [] for str_policy, password in data: policy = parse_poli...
eaeed21766f75657270303ddac34c8dcae8f4f01
Scientific-Computing-at-Temple-Physics/prime-number-finder-gt8mar
/Forst_prime.py
605
4.375
4
# Marcus Forst # Scientific Computing I # Prime Number Selector # This function prints all of the prime numbers between two entered values. import math as ma # These functions ask for the number range, and assign them to 'x1' and 'x2' x1 = int(input('smallest number to check: ')) x2 = int(input('largest number to ...
d40172caa6c5f944dd0db4a8a2b7af65ec861c63
piotrbla/pyExamples
/format_poem.py
580
3.78125
4
from unittest.test.test_case import Test def format_poem(poem): if poem[-1:] == ".": return ".\n".join(x.strip() for x in str.split(poem, '.')) else: return ".\n".join(x.strip() for x in str.split(poem, '.'))[:-1] + poem[-1:] x=[1, 2, 3] a = sum(x)/len(x) print(format_poem('Beautiful is bette...
c38197e38f25c0a4897daf349529adb8371fd860
piotrbla/pyExamples
/chess.py
578
3.609375
4
class Field: def __init__(self, r, c): self.r = r self.c = chr(c + ord('A') - 1) class Board: def __init__(self): self.fields = [] for row in range(1, 9): row_fields = [] for column in range(1, 9): row_fields.append(Field(row, column)) ...
eb2dcb63ce695d4787b4269754005b9ff9074834
piotrbla/pyExamples
/random_stack.py
4,073
3.515625
4
from random import randint from random import seed class element: def __init__(self, data, prev=None): self.data = data self.prev = prev class stos: def __init__(self, first): self.length = 1 self.porownania = 0 self.przypisania = 4 self.last = element(first) ...
7a04c5413d26c1daf88792f0353f5a5ed0872a98
piotrbla/pyExamples
/resistor.py
3,887
3.734375
4
import unittest def encode_resistor_colors(ohms_string): result = "" codes = {0: "black", 1: "brown", 2: "red", 3: "orange", 4: "yellow", 5: "green", 6: "blue", 7: "violet", 8: "gray", 9: "white"} without_ohms = ohms_string.replace(" ohms", "") x = 0 if without_ohms.endswith('k'): ...
83b7c6b2d13a748299802172b49f6cd0f51e1e25
Charnub/python-code
/Python Programming Sheets/Q22.py
284
3.984375
4
myMessage = (input("Enter Message: ")) upperLower = (input("Shout or Whisper?: ")) upperLower = upperLower.lower() if upperLower == "shout": myShout = myMessage.upper() print(myShout) elif upperLower == "whisper": myShout2 = myMessage.lower() print(myShout2)
fe3c86ed4282507f3f96c7f070bc1ac0036db547
Charnub/python-code
/Python Programming Sheets/Q13.py
301
3.796875
4
import random character = (input("Do you want to create a Character?")) character = character.lower() dice1 = random.randint(1,6) dice2 = random.randint(1,12) if character == "yes": calculate = dice2/dice1+10 print("Hit Points: "+(str(calculate))) elif character == "no": exit()
97ec90e598582256b2ba729af7cde46277481412
Charnub/python-code
/Test Files/y10help.py
242
3.96875
4
print("Welcome to The Quiz!") print("Please create a username and password:") name = (str(input("What is your name?"))) age = (str(input("What is your age?"))) name2 = name[:3] username = name2+age print("Your username is: "+username)
7134c88c5828fd1675705ccecc1d9d6ad12f446e
Charnub/python-code
/Python Programming Sheets/Q27.py
145
3.609375
4
def coinToss(): import random if(random.randint(0,1)==0): return "Heads" else: return "Tails" print(coinToss())
90ab247a769e653a54ddc3165106f74e85d83543
kimstone/itp_week_3
/day_3/exercise-daniel.py
597
3.828125
4
import requests import json # using the requests package, we can make API calls to retrieve JSON # and storing it into a variable here called "response" response = requests.get("https://rickandmortyapi.com/api/character") # verify the response status as 200 # print(response) # verify the raw string data of the respo...
1e9988d1becd1cf946dd8d26f614cc0d142edd52
annilq/python
/chapter-9/admin.py
482
3.625
4
from user import User class Privileges(): """docstring for Privileges""" def __init__(self): super().__init__() self.privileges = ["can add post","can delete post","can ban user"] def show_privileges(self): print("the admin ",self.privileges) class Admin(User): """docstring for Admin""" def __init__(self, f...
f72db317acd78d63bae31468bcece656e696a540
Nrams1/CSC1015F_Assignment-2
/pi.py
332
3.984375
4
# calculate pi # neo ramotlou # 15 march 2018 x = 0 fraction = 2 import math p = 2 while x !=2: x = math.sqrt(x+2) fraction = (2/x) p = p*fraction print('Approximation of pi:', round(p, 3)) radius = eval(input('Enter the radius: \n')) print('Area:', round((p*(radius**2)), 3)) ...
35cd940e9184686fb80f549dad3555404537714a
daniel321c/coding_quiz
/leafSum.py
665
3.515625
4
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def sumNumbers(self, root: TreeNode) -> int: self.total = 0 self.getNumber(root, 0) return self.total def getNumber(self, node, carry): ...
1ee05d52209e23c2cacd5b512cb3963b26af6b30
daniel321c/coding_quiz
/filter.py
710
3.625
4
from abc import ABC, abstractmethod class BaseFilter(ABC): def __init__(self, field, constraint): self.field = field self.constraint = constraint @abstractmethod def apply(self, object): print("i am abstract") pass class EquationFilter(BaseFilter): def __init__(sel...
076fbda9c9524d527abe372d12f5ab69659bb100
chz224/Apply-Security-HW1
/HW_1.py
760
3.90625
4
#Cheng Hao Zheng #HW 1 Spell Checker #Github user name: chz224 #import spellchecker library from spellchecker import SpellChecker def main(): spell = SpellChecker() #change the file to the text file you want to spell check #currently spell checking file MisspelledText.txt misspelledFile = o...
f6d7f32228e90e46336cab48bafca14da5be421a
jarbus/epsilon-machine-python
/em/parse_tree_node.py
4,436
3.59375
4
from collections import defaultdict, Counter from typing import Dict, Sequence, List from functools import partial import plantuml import sys class ParseTreeNode: """Node of a parse tree. Arguments: depth: Level of depth in a tree. For roots, depth=0. target_depth: Denoted as D in Crutchfield...
4845e44fa0afcea9f4293f45778f6b4ea0da52b0
jamiegowing/jamiesprojects
/character.py
402
4.28125
4
print("Create your character") name = input("what is your character's name") age = int(input("how old is your character")) strengths = input("what are your character's strengths") weaknesses = input("what are your character's weaknesses") print(f"""You'r charicters name is {name} Your charicter is {age} years old stren...
18c4527e5b18282b5d023fe97dbd880bc0f91796
UPML/python2017
/62.py
1,097
3.6875
4
import random def british_word(word, param): if len(word) >= param + 2: last_to_change = min(param, len(word) - 2) positions = random.sample(range(1, len(word) - 1), last_to_change) characters = [] for j in positions: characters.append(word[j]) random.shuffle(ch...
45822bdb6dc53702eff7f2a899117558bb05e4f0
UPML/python2017
/4.py
812
3.75
4
def memoize(function): memo = {} def wrapper(*args): if args in memo: return memo[args] else: rv = function(*args) memo[args] = rv return rv return wrapper # не сложилось=( @memoize def fib(n): if (n == 0): return 0 if (n ==...
142ecec208f83818157ce4c8dff7495892e5d5d2
yagizhan/project-euler
/python/problem_9.py
450
4.15625
4
# A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, # a2 + b2 = c2 # For example, 32 + 42 = 9 + 16 = 25 = 52. # There exists exactly one Pythagorean triplet for which a + b + c = 1000. # Find the product abc. def abc(): for c in range(1, 1000): for b in range(1, c): ...
004571b005999b28b9913db8d646c82f1e562b1b
peterlew/euler-python
/p14.py
379
3.5
4
results = {1 : 1} def chainLen(n): if n in results: return(results[n]) if n % 2 == 0: result = 1 + chainLen(n // 2) else: result = 1 + chainLen(n * 3 + 1) results[n] = result return result longestChain = 0 longestChainStart = 0 for i in range(1, 1000000): c = chainLen(i) if c > longestChain: longestCh...
1258ef4008a50145318fbd3e8bd13fabc8989cbb
peterlew/euler-python
/p31.py
457
3.625
4
coins = [200, 100, 50, 20, 10, 5, 2, 1] # results dic: (target, max coin index) -> ways to make target # using coins at max index or greater results = {} for i in range(8): results[(0, i)] = 1 def waysToMake(n, ind): if (n, ind) in results: return results[(n, ind)] total = 0 for i in range(ind, 8): coin =...
e7db4be32011e9c773b088453853c24d0c98f4a7
SoyeonHH/Algorithm_Python
/LeetCode/819.py
562
3.5
4
import collections import re paragraph = "Bob hit a ball, the hit BALL flew far after it was hit." banned = ["hit"] # Solution # -------------------------------------------------------------- # 입력값 전처리 words = [word for word in re.sub(r'[^\w]',' ', paragraph) .lower().split() if word not in ...
850cb22e85b943a16b872d0d826b498ab118b90b
SoyeonHH/Algorithm_Python
/LeetCode/206.py
745
3.90625
4
# Definition for singly-linked list. class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next class Solution: # 재귀 구조로 뒤집기 def reverseList_1(self, head: ListNode) -> ListNode: def reverse(node: ListNode, prev: ListNode): if not node...
77b2c0824d422ba288765da390bd2b7c068bdb62
Alston-Tang/Spam-Filter
/proc_mail.py
1,858
3.671875
4
# -*- coding: utf-8 -*- """ This file contains functions of processing emails """ import re from html2text import html2text def get_mail_body(_mail_file): """ Extract the mail body from the mail file. :param mail_file: file contains the raw content of email :type mail_file: str :return: string th...