随笔分类 -  Python

摘要:import time from functools import wraps def timethis(func): ''' Decorator that reports the execution time. ''' @wraps(func) def wrapper(*args, **kwarg 阅读全文
posted @ 2021-11-18 16:15 米开朗菠萝 阅读(110) 评论(0) 推荐(0)
摘要:进程池用multiprocessing.Manager().dict()字典,键值是list 直接用share_write_dict[host].append(tmp_d["sid"])不行,添加后的列表依旧为空, 改为 share_write_dict[host] = [] tmp = share 阅读全文
posted @ 2021-10-13 11:32 米开朗菠萝 阅读(742) 评论(0) 推荐(0)
摘要:Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warme 阅读全文
posted @ 2020-05-06 14:36 米开朗菠萝 阅读(149) 评论(0) 推荐(0)
摘要:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n 阅读全文
posted @ 2020-03-31 22:54 米开朗菠萝 阅读(93) 评论(0) 推荐(0)
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov 阅读全文
posted @ 2020-03-31 22:17 米开朗菠萝 阅读(138) 评论(0) 推荐(0)
摘要:一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶。求该青蛙跳上一个 n 级的台阶总共有多少种跳法。 答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。 示例 1: 输入:n = 2输出:2示例 2: 输入:n = 7输出:21提示: 0 <= n 阅读全文
posted @ 2020-03-31 18:48 米开朗菠萝 阅读(259) 评论(0) 推荐(0)
摘要:写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项。斐波那契数列的定义如下: F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N - 2), 其中 N > 1.斐波那契数列由 0 和 1 开始,之后的斐波那契数就是由之前的两数相加而得出。 答案需要取 阅读全文
posted @ 2020-03-31 18:39 米开朗菠萝 阅读(209) 评论(0) 推荐(0)
摘要:用两个栈实现一个队列。队列的声明如下,请实现它的两个函数 appendTail 和 deleteHead ,分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,deleteHead 操作返回 -1 ) 示例 1: 输入:["CQueue","appendTail","delet 阅读全文
posted @ 2020-03-31 18:28 米开朗菠萝 阅读(118) 评论(0) 推荐(0)
摘要:在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19] 阅读全文
posted @ 2020-03-31 17:33 米开朗菠萝 阅读(124) 评论(0) 推荐(0)
摘要:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of 阅读全文
posted @ 2020-03-31 16:27 米开朗菠萝 阅读(89) 评论(0) 推荐(0)
摘要:Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two di 阅读全文
posted @ 2020-03-31 15:28 米开朗菠萝 阅读(92) 评论(0) 推荐(0)
摘要:Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements of [1, n] 阅读全文
posted @ 2020-03-31 15:20 米开朗菠萝 阅读(100) 评论(0) 推荐(0)
摘要:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexi 阅读全文
posted @ 2020-03-30 12:08 米开朗菠萝 阅读(155) 评论(0) 推荐(0)
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [3,0,1] Output 阅读全文
posted @ 2020-03-30 11:38 米开朗菠萝 阅读(120) 评论(0) 推荐(0)
摘要:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the  阅读全文
posted @ 2020-03-29 20:57 米开朗菠萝 阅读(104) 评论(0) 推荐(0)
摘要:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the arr 阅读全文
posted @ 2020-03-29 20:04 米开朗菠萝 阅读(108) 评论(0) 推荐(0)
摘要:Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] 阅读全文
posted @ 2020-03-29 19:59 米开朗菠萝 阅读(141) 评论(0) 推荐(0)
摘要:At a lemonade stand, each lemonade costs $5. Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bil 阅读全文
posted @ 2020-03-29 17:49 米开朗菠萝 阅读(135) 评论(0) 推荐(0)
摘要:A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one p 阅读全文
posted @ 2020-03-29 17:20 米开朗菠萝 阅读(180) 评论(0) 推荐(0)
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g 阅读全文
posted @ 2020-03-29 13:50 米开朗菠萝 阅读(136) 评论(0) 推荐(0)